[cairo] Drawing/painting multiple images

Sakari Aaltonen sakari.aaltonen at tkk.fi
Sun Aug 31 22:49:41 PDT 2008


Quoting Aron Rubin <aron.rubin at lmco.com>:

> You can scale and translate the drawing context (cairo_t) or the pattern. The
> pattern scaling and translating looks something like this:
>
> pattern = cairo_pattern_create_for_surface (image1);
> cairo_pattern_set_filter (pattern, CAIRO_FILTER_GOOD);
> sx = ((double)cairo_image_surface_get_width (image1)) / 0.15;
> sy = ((double)cairo_image_surface_get_height (image1)) / 0.15;
> cairo_matrix_init_scale (&matrix, sx, sy);
> cairo_matrix_translate (&matrix, -image1_x, -image1_y);
> cairo_pattern_set_matrix (pattern, &matrix);
> cairo_set_source (cr, pattern);
> cairo_pattern_destroy (pattern);
> cairo_paint (cr);
>
> pattern = cairo_pattern_create_for_surface (image2);
> cairo_pattern_set_filter (pattern, CAIRO_FILTER_GOOD);
> sx = ((double)cairo_image_surface_get_width (image2)) / 0.15;
> sy = ((double)cairo_image_surface_get_height (image2)) / 0.15;
> cairo_matrix_init_scale (&matrix, sx, sy);
> cairo_matrix_translate (&matrix, -image2_x, -image2_y);
> cairo_pattern_set_matrix (pattern, &matrix);
> cairo_set_source (cr, pattern);
> cairo_pattern_destroy (pattern);
> cairo_paint (cr);

Thank you. My problem seems to have been scaling. I want to include  
images from several sources such that no matter the initial size (in  
pixels), the final size
on my Cairo surface is the same. When I - erroneously - scaled that  
surface (repeatedly), coordinates, say, were "scaled", too, and  
quickly became nonsensical.

Sakari A




More information about the cairo mailing list