[cairo] Writing Surface to PNG based on Window Context: POSSIBLE?

darethehair darethehair at gmail.com
Fri Mar 20 15:31:27 PDT 2009


OK, for my 2nd newbie question...

I know sortof how to read in a PNG, draw on it, and write it back out 
again to another PNG:

import cairo
from math import pi

s = cairo.ImageSurface.create_from_png('input.png')
p = cairo.SurfacePattern(s)
t = cairo.ImageSurface(cairo.FORMAT_ARGB32, 800, 480)
ctx = cairo.Context(t)
ctx.set_source(p)
ctx.paint()
ctx.set_source_rgba(0.5,0.5,0.5)
ctx.arc(10,10, 20, 0, 2 * pi)
ctx.fill()
ctx.stroke()
t.write_to_png('output.png')

However, what if my 'context' wasn't an 'ImageSurface', but was instead 
a 'Window'?

ctx = widget.window.cairo_create()

How does one invoke the 'write_to_png' in that situation?  The reason I 
ask this is that I would like to be able to draw on the 'screen', but 
also re-direct to a PNG (or whatever) file if I want to.

Thanks!

Dare

P.S. Sorry for the terminology -- all this 
context/surface/pattern/source stuff is rather confusing at first...


More information about the cairo mailing list