[cairo] Apply / Composite smaller PNGs onto large background PNG?

Uli Schlachter psychon at znc.in
Wed Jun 13 10:08:58 PDT 2012


On 13.06.2012 18:34, Jim Norton wrote:
> I'm somewhat new to GTK and very new to Cairo. I've been tasked to  
> create an application that needs to take a PNG as a background and  
> composite multiple PNG files that contains letters and numbers onto  
> the background PNG so that I end up with a single PNG that can then be  
> transformed, rotated, scaled etc. Any hints, tutorials, code samples  
> that I might find useful? As is the case with GTK, the Cairo  
> documentation appears somewhat lacking for a beginner trying to do  
> something more complex than drawing shapes.

The basic approach is to load each PNG into a cairo surface. Then, to draw the
content of surface a to surface b at the coordinates x, y, you would do:

  cairo_t *cr = cairo_create(b);
  cairo_set_source_surface(cr, a, x, y);
  cairo_paint(cr);
  cairo_destroy(cr);

Of course, you don't have to create and destroy the cairo_t all the time, but
can use it for drawing multiple surfaces one after another.

Hope this helps sending you in the right direction.

Uli
-- 
- Captain, I think I should tell you I've never
  actually landed a starship before.
- That's all right, Lieutenant, neither have I.


More information about the cairo mailing list