How can I grab the color of a pixel on my desktop? (Linux)
Question: I want to grab the color of a pixel with known coordinates on my Linux
desktop.

Until now, I've used `"import -window SomeWindow -crop 1x1+X+Y /tmp/grab.jpg"`
then extracting the pixel value using Python and
[PIL](http://en.wikipedia.org/wiki/Python%5FImaging%5FLibrary).

This does the job, but since import grabs the whole window before cropping,
it's very slow :(

Are there any clever way to grab the color of only one pixel? I know both
relative (window) and absolute coordinates.

A Python or shell script would be preferable, but if you know some clever
C/[X11](http://en.wikipedia.org/wiki/X%5FWindow%5FSystem) functions, also
please let me know :)


Answer: 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.

