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
cs = cairo.ImageSurface(cairo.FORMAT_RGB24, 1, 1);
cairo_surface = cairo.ImageSurface(cairo.FORMAT_RGB24, 1, 1);
cr = cairo.Context(cs)
cairo_context = cairo.Context(cairo_surface)
# translate surface so that target pixel is at 0, 0
# translate xlib_surface so that target pixel is at 0, 0
cr.set_source_surface(self.tw.turtle_canvas, -x, -y)
cairo_context.set_source_surface(xlib_surface, -x, -y)
cr.rectangle(0,0,1,1)
cairo_context.rectangle(0,0,1,1)
cr.set_operator(cairo.OPERATOR_SOURCE)
cairo_context.set_operator(cairo.OPERATOR_SOURCE)
cr.fill()
cairo_context.fill()
cs.flush() # ensure all writing is done
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)