<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: getpixel code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 07 Sep 2008 20:35:06 GMT</pubDate>
    <description>DZone Snippets: getpixel code</description>
    <item>
      <title>Get pixel colors of an image</title>
      <link>http://snippets.dzone.com/posts/show/632</link>
      <description>Pys60 now has a decent Canvas and Image class.&lt;br /&gt;We can draw many shapes and color them.&lt;br /&gt;However, one important feature is missing, ie. getpixel().&lt;br /&gt;So, you can only 'write' but not 'read' from graphics.&lt;br /&gt;&lt;br /&gt;To get around this problem, I write a small library that&lt;br /&gt;add 'getpixel' to the Image class.&lt;br /&gt;Now, you can call im.getpixel(x,y) and get an (R,G,B) tuple.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# some setup&lt;br /&gt;from graphics import *&lt;br /&gt;im = screenshot()  # sample image&lt;br /&gt;&lt;br /&gt;# http://larndham.net/service/pys60/getpixel.py&lt;br /&gt;import getpixel&lt;br /&gt;getpixel.enable(im)  # magically give Image.getpixel()&lt;br /&gt;r, g, b = im.getpixel(0,0)  # top left corner&lt;br /&gt;print 'Red: %s, Green:%s, Blue:%s' % (r,g,b)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Now you can do some easy image processing with getpixel.&lt;br /&gt;&lt;br /&gt;Implementation note&lt;br /&gt;===================&lt;br /&gt;- This is a pure python module&lt;br /&gt;- It saves an image as an uncompressed PNG file&lt;br /&gt;- It reads pixel data from the file and attach it to the image.&lt;br /&gt;- You need to call enable() every time you change the image.</description>
      <pubDate>Mon, 05 Sep 2005 03:46:03 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/632</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
