Features/GTK3/Porting: Difference between revisions
| Line 256: | Line 256: | ||
</pre> | </pre> | ||
To read a pixel... | To read a pixel from the xlib surface... | ||
<pre> | <pre> | ||
# create a new 1x1 cairo surface | # create a new 1x1 cairo surface | ||
cairo_surface = cairo.ImageSurface(cairo.FORMAT_RGB24, 1, 1); | |||
cairo_context = cairo.Context(cairo_surface) | |||
# translate | # translate xlib_surface so that target pixel is at 0, 0 | ||
cairo_context.set_source_surface(xlib_surface, -x, -y) | |||
cairo_context.rectangle(0,0,1,1) | |||
cairo_context.set_operator(cairo.OPERATOR_SOURCE) | |||
cairo_context.fill() | |||
cairo_surface.flush() # ensure all writing is done | |||
# Read the pixel | # Read the pixel | ||
return (ord(pixels[2]), ord(pixels[1]), ord(pixels[0]), 0) | return (ord(pixels[2]), ord(pixels[1]), ord(pixels[0]), 0) | ||