[cairo] Drawing/painting multiple images

Gerdus van Zyl gerdusvanzyl at gmail.com
Fri Aug 29 11:26:03 PDT 2008


cairo_paint (cr); <<existing

image2 = cairo_image_surface_create_from_png ("kitten.png");
cairo_set_source_surface (cr, image2, x, y);

cairo_move_to( cr, x, y);
cairo_paint (cr);

to place a second image at x,y

You can also fill a shape using the source:
cairo_rectangle(cr,x,y,200,200) << or any shape/path
cairo_fill(cr);

~Gerdus

On Fri, Aug 29, 2008 at 6:26 PM, Sakari Aaltonen <sakari.aaltonen at tkk.fi> wrote:
> I would like to include several images (PNG's) on a Cairo surface.
> I have seen examples of how to do this with one image, say at
>   http://zetcode.com/tutorials/cairographicstutorial/cairoimages/
> or
>   http://cairographics.org/samples/
> But I cannot figure out the correct way to handle multiple ones.
> My current code looks like this:
> -------------------------------------------------------------
>    cairo_surface_t *surface;
>    double scale = 300;
>    cairo_t *cr;
>    int imagw, imagh;
>    cairo_surface_t *image;
>
>    surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
>                                         scale, scale);
>    cr = cairo_create(surface);
>    cairo_scale(cr, scale, scale);
>    cairo_set_line_width(cr, 0.10);
>
>    cairo_set_source_rgb (cr, 0.4, 0.0, 0.6);
>    cairo_rectangle (cr, 0.1, 0.1, 0.5, 0.8);      // rectangle outline
>    cairo_stroke(cr);
>
>    image = cairo_image_surface_create_from_png ("button.png");
>    imagw = cairo_image_surface_get_width (image);
>    imagh = cairo_image_surface_get_height (image);
>    cairo_scale (cr, 0.15/imagw, 0.15/imagh);
>    cairo_set_source_surface (cr, image, 0, 0);
>
>    cairo_paint (cr);
>    cairo_surface_destroy (image);
>
>    cairo_destroy(cr);
>    cairo_surface_destroy (surface);
> ------------------------------------------------------------------
>
> This seems to work in that <button.png> is drawn. But I don't understand
> how one is supposed to paint another image on the same surface. Or even,
> how to put the single image somewhere else, that is, not at the upper
> left corner.
>
>
> Thank you in advance,
> Sakari Aaltonen
>
>
> _______________________________________________
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
>


More information about the cairo mailing list