<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: size code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 07:46:40 GMT</pubDate>
    <description>DZone Snippets: size code</description>
    <item>
      <title>J2ME - Rescale Image</title>
      <link>http://snippets.dzone.com/posts/show/3257</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;private Image rescaleImage(Image image, int width, int height)&lt;br /&gt;	{&lt;br /&gt;		int sourceWidth = image.getWidth();&lt;br /&gt;		int sourceHeight = image.getHeight();&lt;br /&gt;	&lt;br /&gt;		Image newImage = Image.createImage(width, height);&lt;br /&gt;		Graphics g = newImage.getGraphics();&lt;br /&gt;		&lt;br /&gt;		for(int y=0; y&lt;height; y++)&lt;br /&gt;		{&lt;br /&gt;			for(int x=0; x&lt;width; x++)&lt;br /&gt;			{&lt;br /&gt;				g.setClip(x, y, 1, 1);&lt;br /&gt;				int dx = x * sourceWidth / width;&lt;br /&gt;				int dy = y * sourceHeight / height;&lt;br /&gt;				g.drawImage(image, x-dx, y-dy, Graphics.LEFT | Graphics.TOP);&lt;br /&gt;			}&lt;br /&gt;		}&lt;br /&gt;		&lt;br /&gt;		return Image.createImage(newImage);&lt;br /&gt;	}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 09 Jan 2007 02:08:25 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3257</guid>
      <author>whitetiger ()</author>
    </item>
    <item>
      <title>Linux - XTerm font size</title>
      <link>http://snippets.dzone.com/posts/show/2993</link>
      <description>// Aumenta la dimensione del carattere sul terminale&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;xterm -geometry 640x480 -fn *-fixed-*-*-*-20-*&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 13 Nov 2006 22:53:12 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2993</guid>
      <author>whitetiger ()</author>
    </item>
    <item>
      <title>Split String into roughly equal-sized chunks.</title>
      <link>http://snippets.dzone.com/posts/show/2631</link>
      <description>Split a string into an array of roughly equal sized chunks based on a string or regular expression delimiter.&lt;br /&gt;Delimiter is preserved in output.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class String&lt;br /&gt;  def chunk_string(average_segment_size = 40, sclice_on = /\s+/)&lt;br /&gt;    out = []&lt;br /&gt;    slices_estimate = self.size.divmod(average_segment_size)&lt;br /&gt;    slice_count = (slices_estimate[1] &gt; 0 ? slices_estimate[0] + 1 : slices_estimate[0])&lt;br /&gt;    slice_guess = self.size / slice_count&lt;br /&gt;    previous_slice_location = 0&lt;br /&gt;    (1..slice_count - 1).each do&lt;br /&gt;      |i|&lt;br /&gt;      slice_location = self.nearest_split(slice_guess * i, sclice_on)&lt;br /&gt;      out &lt;&lt; self.slice(previous_slice_location..slice_location)&lt;br /&gt;      previous_slice_location = slice_location + 1&lt;br /&gt;    end&lt;br /&gt;    out &lt;&lt; self.slice(previous_slice_location..self.size)&lt;br /&gt;    out&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  def nearest_split(slice_start, slice_on)&lt;br /&gt;    left_scan_location  = (self.slice(0..slice_start).rindex(slice_on)).to_i&lt;br /&gt;    right_scan_location = (self.slice((slice_start+1)..self.size).index(slice_on)).to_i + slice_start&lt;br /&gt;    ((slice_start - left_scan_location) &lt; (right_scan_location - slice_start) ? left_scan_location : right_scan_location)&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 21 Sep 2006 00:29:28 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2631</guid>
      <author>duncanbeevers (Duncan Beevers)</author>
    </item>
    <item>
      <title>file-size-comparison-ctx - find files matching size criteria; dialected interface</title>
      <link>http://snippets.dzone.com/posts/show/2091</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;file-size-comparison-ctx: context [&lt;br /&gt;    =negate-op?: none&lt;br /&gt;    =or-equal?: none&lt;br /&gt;    =op: none&lt;br /&gt;    =size: 0&lt;br /&gt;    =size-mul: 1&lt;br /&gt;    =parse-end-mark: none&lt;br /&gt;&lt;br /&gt;    make-lit-word: func [val] [to lit-word! :val]&lt;br /&gt;    lit-lesser: make-lit-word "&lt;"&lt;br /&gt;    lit-greater: make-lit-word "&gt;"&lt;br /&gt;    lit-lesser-or-equal: make-lit-word "&lt;="&lt;br /&gt;    lit-greater-or-equal: make-lit-word "&gt;="&lt;br /&gt;&lt;br /&gt;    size=: [&lt;br /&gt;        (=size-mul: 1)&lt;br /&gt;        set =size number!&lt;br /&gt;        opt [&lt;br /&gt;            'bytes ; no change to size-mul&lt;br /&gt;            | ['kilobytes | 'KB] (=size-mul: 1024.0)&lt;br /&gt;            | ['megabytes | 'MB] (=size-mul: 1048576.0)&lt;br /&gt;            | ['gigabytes | 'GB] (=size-mul: 1073741824.0)&lt;br /&gt;        ]&lt;br /&gt;        (=size: =size * =size-mul)&lt;br /&gt;    ]&lt;br /&gt;    word-comparison=: [&lt;br /&gt;        [&lt;br /&gt;            ['more | 'bigger | 'larger | 'greater] (=op: 'greater)&lt;br /&gt;            | ['less | 'smaller] (=op: 'lesser)&lt;br /&gt;        ] 'than&lt;br /&gt;        opt ['or 'equal 'to (=or-equal?: true)]&lt;br /&gt;    ]&lt;br /&gt;    lit-comparison=: [&lt;br /&gt;        lit-lesser             (=or-equal?: false  =op: 'lesser)&lt;br /&gt;        | lit-greater          (=or-equal?: false  =op: 'greater)&lt;br /&gt;        | lit-lesser-or-equal  (=or-equal?: true   =op: 'lesser)&lt;br /&gt;        | lit-greater-or-equal (=or-equal?: true   =op: 'greater)&lt;br /&gt;    ]&lt;br /&gt;    rules=: [&lt;br /&gt;        (=negate-op?: =or-equal?: =op: =parse-end-mark: none)&lt;br /&gt;        opt 'if opt ['size | size?]&lt;br /&gt;        opt [['no | 'not] (=negate-op?: true)]&lt;br /&gt;        [word-comparison= | lit-comparison=]&lt;br /&gt;        (if =negate-op? [=op: pick [greater lesser] =op = 'lesser])&lt;br /&gt;        (=op: to word! rejoin [=op either =or-equal? ['-or-equal] [""] '?])&lt;br /&gt;        size=&lt;br /&gt;        =parse-end-mark:&lt;br /&gt;    ]&lt;br /&gt;&lt;br /&gt;    set 'size-comparison-cmd? func [input [block!]] [&lt;br /&gt;        parse input rules=&lt;br /&gt;        return =parse-end-mark&lt;br /&gt;    ]&lt;br /&gt;&lt;br /&gt;    set 'make-file-size-comparison-func func [spec] [&lt;br /&gt;        parse spec rules=&lt;br /&gt;        either =parse-end-mark [&lt;br /&gt;            func [file] reduce [=op 'size? 'file =size]&lt;br /&gt;        ] [none]&lt;br /&gt;    ]&lt;br /&gt;&lt;br /&gt;    set 'files-matching-size-spec func [&lt;br /&gt;        files [block!]&lt;br /&gt;        spec [block!]&lt;br /&gt;    ][&lt;br /&gt;        if match?: make-file-size-comparison-func spec [&lt;br /&gt;            collect 'keep [&lt;br /&gt;                foreach file files [if match? file [keep: file]]&lt;br /&gt;            ]&lt;br /&gt;        ]&lt;br /&gt;    ]&lt;br /&gt;]&lt;br /&gt;;foreach file files-matching-size-spec read %. [&gt;= 64 kb] [print [file size? file]]&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 23 May 2006 21:43:57 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2091</guid>
      <author>gregg.irwin (Gregg Irwin)</author>
    </item>
    <item>
      <title>New camera module</title>
      <link>http://snippets.dzone.com/posts/show/397</link>
      <description>A few days ago, I posted an example of how to take&lt;br /&gt;a photo with py_s60 1.1.0. But now, a new and better&lt;br /&gt;version (1.1.3) is released. The camera module has&lt;br /&gt;improved significantly.&lt;br /&gt;&lt;br /&gt;Now it can&lt;br /&gt;- use different sizes (640x480 and 160x120 in my case)&lt;br /&gt;- use zoom (0 or 1 in my case)&lt;br /&gt;- take photos at 12, 16 or 24-bit color ('RGB12', 'RGB16', 'RGB')&lt;br /&gt;- using flash ('none', 'auto', 'forced', 'fill_in', 'red_eye_reduce')&lt;br /&gt;- set white-balance and exposure (I use 'auto' for both,&lt;br /&gt;  but sometimes I may use 'night' exposure)&lt;br /&gt;- return an image object which can save in 'jpg' or 'png' format&lt;br /&gt;&lt;br /&gt;You can see that these have good default values&lt;br /&gt;&lt;code&gt; # copy from camera.py&lt;br /&gt;def take_photo(&lt;br /&gt;  mode='RGB16',&lt;br /&gt;  size=(640, 480),&lt;br /&gt;  zoom=0,&lt;br /&gt;  flash='none',&lt;br /&gt;  exposure='auto',&lt;br /&gt;  white_balance='auto'):&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;So the simplest example is&lt;br /&gt;&lt;code&gt;&lt;br /&gt;import camera&lt;br /&gt;im = camera.take_photo()  # use all default values&lt;br /&gt;im.save(u'C:\\test.jpg')&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;You can see what you can set on your phone&lt;br /&gt;&lt;code&gt;&lt;br /&gt;from camera import *&lt;br /&gt;print image_modes()&lt;br /&gt;print image_sizes()&lt;br /&gt;print max_zoom()&lt;br /&gt;print flash_modes()&lt;br /&gt;print exposure_modes()&lt;br /&gt;print white_balance_modes()&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 19 Jun 2005 21:56:26 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/397</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
