DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Get Pixel Colors Of An Image

10.26.2005
| 7682 views |
  • submit to reddit
        I wrote <a href=http://www.bigbold.com/snippets/posts/show/632>a hack</a> to get the color of a pixel.
Now pys60 1.2 has support for getpixel (though undocumented).
Cyke64 has shown me in <a href=http://discussion.forum.nokia.com/forum/showpost.php?p=168137&postcount=8>an example</a>.
>>> from graphics import Image
>>> im = Image.new((10,10))   # create a new 10x10 image
>>> im.clear(0xff0000)        # make it all red
>>> im.getpixel((0,0))   # top-left is red
[(255, 0, 0)]
>>> im.getpixel([(0,0), (10,10)])  # you can get multiple points
[(255, 0, 0), (255, 0, 0)]
>>>