[cairo] Pasting a png image on another

Anisha Kaul anisha.kaul at hitechroboticsystemz.com
Sat Mar 6 01:32:01 PST 2010


Alex,

Many thanks for bothering to reply,

I've managed to paste 2 png images on a base png image w.r.t Cairo and below I have presented the functional code so that it helps 
someone else:

and the important links w.r.t following code are:

http://zetcode.com/tutorials/cairogr...l/compositing/
and
http://zetcode.com/tutorials/cairogr...l/shapesfills/
	

[CODE]
	cairo_surface_t *surface  = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 240, 80);
        cairo_t         *cr       = cairo_create (surface);

	cairo_t         *first_cr;
	cairo_t         *second_cr;
	cairo_t         *third_cr;
	cairo_surface_t *a;
	cairo_surface_t *b;
	cairo_surface_t *c;
	
	a = cairo_surface_create_similar (cairo_get_target (cr), CAIRO_CONTENT_COLOR_ALPHA, 240, 80);
	b = cairo_surface_create_similar (cairo_get_target (cr), CAIRO_CONTENT_COLOR_ALPHA, 240, 80);
	c = cairo_surface_create_similar (cairo_get_target (cr), CAIRO_CONTENT_COLOR_ALPHA, 240, 80);
	
	a = cairo_image_surface_create_from_png ("cairo-demo.png");
	b = cairo_image_surface_create_from_png ("box.png");
	c = cairo_image_surface_create_from_png ("base.png");
		
	first_cr  = cairo_create (a);
	second_cr = cairo_create (b);
	third_cr  = cairo_create (c);
	
	cairo_stroke (first_cr);
	cairo_stroke (second_cr);
	cairo_stroke (third_cr);
	
	// Pasting the Map on the base image
	cairo_set_operator       (third_cr, (cairo_operator_t)5);
	cairo_set_source_surface (third_cr, a, 220, 80);
	cairo_paint              (third_cr);
	
	cairo_set_source_surface (cr, c, 20, 20);
	cairo_paint(cr);
	
	cairo_surface_write_to_png (c, "different.png");

	// Pasting the Label on the base image
	cairo_set_operator       (third_cr, (cairo_operator_t)5);
	cairo_set_source_surface (third_cr, b, -20, 80);
	cairo_paint              (third_cr);
	
	cairo_set_source_surface (cr, c, 20, 20);
	cairo_paint(cr);
	
	cairo_surface_write_to_png (c, "different.png");
[/CODE]

Regards,
Anisha Kaul





-------------------------------------
Hi-Tech Gears Limited, Gurgaon, India






More information about the cairo mailing list