[cairo] how to copy a part from one surface to another ?

Carl Worth cworth at cworth.org
Wed Jun 27 07:11:02 PDT 2007

On Wed, 27 Jun 2007 11:57:31 +0200, wrote:
> destSurface->set_source(srcSurface, xDest, yDest, xSrc, ySrc, widthSrc, heightSrc)

I'll write in C, and hopefully you can trivially translate to your
language of interest. Given cr that's targeting dest_surface you can

	cairo_set_source_surface (cr, src_surface, x_dest - x_src, y_dest - y_src);
	cairo_rectangle (cr, x_dest, y_dest, width, height);
	cairo_fill (cr);

If your source surface has any alpha, that will blend it over the
destination. If you want to copy the alpha directly, you'll want to
use the SOURCE operator something like this:

	cairo_save (cr);
	cairo_rectangle (cr, ...);
	cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
	cairo_fill (cr);
	cairo_restore (cr);

If your source surface has no alpha then you can use either one---it
doesn't matter.

And do notice that cairo isn't providing a "copy surface" primitive
here, but instead that you're simply drawing something and using a
surface as the source pattern. So you can similarly draw anything,
(complex polygons, text, etc.), and have it be patterned with the

Have fun with cairo,

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://cairographics.org/archives/cairo/attachments/20070627/53c3afaf/attachment.pgp 

More information about the cairo mailing list