Line 259: |
Line 259: |
| | | |
| <pre> | | <pre> |
− | # Map the xlib surface onto a pixmap | + | # create a new 1x1 cairo surface |
− | pixmap = gtk.gdk.Pixmap(None, w, h, 24)
| + | cs = cairo.ImageSurface(cairo.FORMAT_RGB24, 1, 1); |
− | cairo_context = pixmap.cairo_create()
| + | cr = cairo.Context(cs) |
− | cairo_context.set_source_surface(xlib_surface, 0, 0)
| + | # translate surface so that target pixel is at 0, 0 |
− | cairo_context.paint()
| + | cr.set_source_surface(self.tw.turtle_canvas, -x, -y) |
− | | + | cr.rectangle(0,0,1,1) |
| + | cr.set_operator(cairo.OPERATOR_SOURCE) |
| + | cr.fill() |
| + | cs.flush() # ensure all writing is done |
| # Read the pixel | | # Read the pixel |
− | pixel = pixmap.get_image(x, y, 1, 1).get_pixel(0, 0)
| + | return (ord(pixels[2]), ord(pixels[1]), ord(pixels[0]), 0) |
− | return(int((pixel & 0xFF0000) >> 16), # red | |
− | int((pixel & 0x00FF00) >> 8), # green
| |
− | int((pixel & 0x0000FF) >> 0), 0) # blue
| |
| </pre> | | </pre> |
| | | |