We can draw many shapes and color them.
However, one important feature is missing, ie. getpixel().
So, you can only 'write' but not 'read' from graphics.
To get around this problem, I write a small library that
add 'getpixel' to the Image class.
Now, you can call im.getpixel(x,y) and get an (R,G,B) tuple.
1 2 # some setup 3 from graphics import * 4 im = screenshot() # sample image 5 6 # http://larndham.net/service/pys60/getpixel.py 7 import getpixel 8 getpixel.enable(im) # magically give Image.getpixel() 9 r, g, b = im.getpixel(0,0) # top left corner 10 print 'Red: %s, Green:%s, Blue:%s' % (r,g,b)
Now you can do some easy image processing with getpixel.
Implementation note
===================
- This is a pure python module
- It saves an image as an uncompressed PNG file
- It reads pixel data from the file and attach it to the image.
- You need to call enable() every time you change the image.
thanks for the above code and getpixel.py file
but i m getting a few problems like
1) from graphics import *
ImportError: No module named graphics
2) r, g, b = im.getpixel(0,0) # top left corner
TypeError: getpixel() takes exactly 2 arguments (3 given)
Is this normal ??
Thanks
Ravi