[cairo] gtk, cairo and surfaces
Gerdus van Zyl
gerdusvanzyl at gmail.com
Sat May 23 04:10:16 PDT 2009
I seem to remember the following also working (on win32 not sure about gtk):
tsurf = ctx.get_target() #get surface from context
tsurf.write_to_png("screen.png")
Just as an aside the code you listed:
## Trying to 'capture' my self.context into a pattern.
self.context.push_group()
p=self.context.pop_group()
will not work because push/pop group only captures cairo calls
betweeen them, so you would need to repeat the drawing between those
calls.
~Gerdus
On Sat, May 23, 2009 at 12:48 PM, Hakki Dogusan <dogusanh at tr.net> wrote:
> Hi,
>
> Donn wrote:
>> Hi,
>> Sorry if I am being thick, but I can't get anywhere with this. I am scraping
>> the net far and wide, so perhaps something will come-up.
>>
>> I am using pygtk and python-cairo. I have a DrawingArea which gets an expose
>> event. In that event one draws stuff with a context; there is no hint of
>> where/what the surface is (I can't find any).
>>
>> I want to output a png of what is being drawn to the window. Can anyone point
>> me in the right direction?
>>
>> Some code:
>>
>> class Stack(gtk.DrawingArea):
>>
>> ...stuff...
>>
>> def _expose(self, widget, event):
>> self.context = widget.window.cairo_create()
>>
>> Draw stuff to self.context ...
>
> Take this drawing commands to a subroutine,ie. DrawStuff(ctx). Call it here:
> DrawStuff(self.context)
>>
>>[snipped rest of def _expose
>
> Write a subroutine for png out, ie.
> def OutToPNG()
> out = cairo.ImageSurface(cairo.FORMAT_ARGB32,self.w,self.h)
> ctxout = cairo.Context( out )
> DrawStuff(ctxout)
> out.write_to_png("somefile%d.png" % self.outpic )
> self.outpic += 1
> destroy ctxout
> destroy out
>
>>
>> Thanks,
>> \d
>
>
> --
> Regards,
> Hakki Dogusan
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
>
More information about the cairo
mailing list