[cairo] how to scale an image - correction
Bertram Felgenhauer
bertram.felgenhauer at googlemail.com
Wed Jan 21 06:25:33 PST 2009
Kelvin Cheng wrote:
> Hi,
> This is a correction to my previous question. The cairo_matrix_init_scale
> should be 2.0 instead of 0.5.
> Even when it is 2.0, the code still does reduce the image by 50%. Any
> idea ?
Isn't that what you wanted?
> I am trying to scale an image by 50 %.
Try this:
cairo_save(cr);
cairo_translate(cr, target_x, target_y);
cairo_scale(cr, 0.5, 0.5);
// note: it's important to set the source after setting up the
// user space transformation.
cairo_set_source_surface(cr, local_surf, 0, 0);
cairo_paint(cr);
cairo_restore(cr);
> I tried with the following code but it does not work:
>
> cairo_save(cr);
> cairo_set_source_surface(cr, local_surf, target_x, target_y);
>
> // these 2 lines are used for scaling
> cairo_pattern_set_matrix (cairo_get_source(board->cr), &matrix);
What is 'matrix' here?
In any case, the pattern matrix transforms coordinates from user space
to pattern space; multiplying the coordinates by 2 will result in the
appearance of the pattern to shrink to 50% its original size.
HTH,
Bertram
More information about the cairo
mailing list