[cairo] How to copy one cairo_t's context to another?

Mikael Hallendal micke at imendio.com
Mon Aug 13 03:50:43 PDT 2007


13 aug 2007 kl. 12.26 skrev Magicloud Magiclouds:

Hi,

> Dear,
>     I created a cairo_t from: layer =
> cairo_create(cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
> rect->width, rect->height)). And draw something on it. Then I want to
> copy them to the main cairo_t. How to do that?

> Thanks.


First off all that code will leak the surface created and you need it  
to be able to draw it onto the main cairo_t (called main_cairo_t below).

You'd want to do something along the lines of:

surface = cairo_iamge_surface_create (CAIRO_FORMAT_ARGB32, rect- 
 >width, rect->height);
layer = cairo_create (surface);

/* Draw something on it */

/* Clean up the context */
cairo_destroy (layer);

/* Draw on the main surface with offset (offset_x, offset_y) */
cairo_set_source_surface (main_cairo_t, surface, offset_x, offset_y);
cairo_paint (main_cairo_t);
cairo_surface_destroy (surface);

/* Carry on */

Hope it helps,
  Mikael Hallendal

--
Imendio AB, http://www.imendio.com




More information about the cairo mailing list