[cairo] Drawing/filling image as a pattern

Ravindra rkumar at novell.com
Thu Mar 25 07:57:29 PST 2004


On Fri, 2004-03-19 at 21:47, Ravindra wrote:
> Hello,
>  I want to use an Image as a pattern when I draw/fill any figure using
> Cairo. Unfortunately, I'm getting no clues how to get it done :-(. The
> image might also need to be flipped along X or Y axis or both depending
> on the requirement. I'm trying to implement the functionality of texture
> brush of MS GDI+.

So finally, I was able to do it with some help from Pippin on IRC.

Following can be used to draw an image over a surface,

// start
pattern = cairo_surface_create_for_image (...);
cairo_surface_set_matrix (pattern, matrix);
cairo_surface_set_repeat (pattern, 1);
cairo_set_pattern (ct, pattern);
cairo_surface_destroy (pattern);
// end

Following can be used to flip the image along X-axis,

// start
pattern = cairo_surface_create_for_image (...);
cairo_matrix_translate (matrix, width, 0);
/* scale in -X direction to flip along X */
cairo_matrix_scale (matrix, -1.0, 1.0);
cairo_surface_set_matrix (pattern, matrix);
cairo_show_surface (ct, pattern, width, height);
cairo_surface_destroy (pattern);
// end

Thanks for all the help!

Regards,
Ravindra





More information about the cairo mailing list