[cairo] erase memory

Steve Chaplin stevech1097 at yahoo.com.au
Wed Dec 7 02:59:00 PST 2005


On Tue, 2005-12-06 at 16:06 +0100, Ccx wrote:
> Hello
> I'm using pycairo and mod_python to generate server-side generated web
> graphics.
> All works fine except the memory block used for drawing isn't cleared in
> any way, so strange artifacts appears sometimes on images.
> How can I clear the memory? Note that I don't want to fill the
> background with color, I want it to be transparent.
> Thnx
> 
> The script is below:
> 
> from mod_python import apache
> import cairo
> import cStringIO
> 
> class CairoHandler:
>         def __init__(self,width,height,format=cairo.FORMAT_ARGB32):
>                 self.sfc=cairo.ImageSurface(format,width,height)
>                 self.ctx = cairo.Context(self.sfc)
>                 self.width = width
>                 self.height = height
>         def tostring(self):
>                 buffer = cStringIO.StringIO()
>                 self.sfc.write_to_png(buffer)
>                 str = buffer.getvalue()
>                 buffer.close()
>                 return str
> 
> def image(w,h,cmd):
>     ch = CairoHandler(int(w),int(h))
>     ctx = ch.ctx
>    
>     # DRAWING
>     # ...
> 
>     return ch.tostring()
> 
> def handler(req):      
>         req.content_type="image/png"
>         data=req.uri.split('/').pop().strip('.png').split('x',2)
>         cmd=data[2]
>         h=data[1]
>         w=data[0]
>         req.write(image(w,h,cmd))
>         return apache.OK
> 
from the cairo/PORTING_GUIDE:

Erasing a surface to transparent
--------------------------------
...
Now:	cairo_set_source_rgba (cr, 0., 0., 0., 0.);
	cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
	cairo_paint (cr);

    or:	cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR);
	cairo_paint (cr);

In Python that would be:
ctx.set_operator (cairo.OPERATOR_CLEAR)
ctx.paint()

Steve

Send instant messages to your online friends http://au.messenger.yahoo.com 


More information about the cairo mailing list