This does the trick, but requires python-gtk:
import gtk.gdk
import sys
def PixelAt(x, y):
w = gtk.gdk.get_default_root_window()
sz = w.get_size()
pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB,False,8,sz[0],sz[1])
pb = pb.get_from_drawable(w,w.get_colormap(),0,0,0,0,sz[0],sz[1])
pixel_array = pb.get_pixels_array()
return pixel_array[y][x]
print PixelAt(int(sys.argv[1]), int(sys.argv[2]))
On Ubuntu 9.10, this also requires python-numpy or it segfaults the python interpreter on the get_pixels_array
line. Ubuntu 10.04 it still has this requirement, or it causes an ImportError regarding numpy.core.multiarray.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…