[cairo] how to scale an image

Kelvin Cheng KCheng at extracomm.com
Tue Jan 20 20:50:43 PST 2009


Hello,

I am trying to scale an image by 50 %.

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);
        cairo_pattern_set_filter(cairo_get_source(board->cr), 
CAIRO_FILTER_BEST);

        cairo_paint(cr);
        cairo_restore(cr);

Another attempt is like this:

        cairo_matrix_t matrix;
        cairo_matrix_init_scale (&matrix, 0.5, 0.5);
        cairo_pattern_t* pattern = 
cairo_pattern_create_for_surface(my_surface);
        cairo_pattern_set_matrix (pattern, &matrix);
        cairo_pattern_set_filter(pattern, CAIRO_FILTER_BEST);

        cairo_set_source(cr , pattern);
        cairo_rectangle(cr, x, y, w, h);
        cairo_fill(cr);

But it also does not work.

What is the correct way to do this ? Thanks.

Regards,
Kelvin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cairographics.org/archives/cairo/attachments/20090121/88708cf3/attachment-0001.htm 


More information about the cairo mailing list