[cairo] how to scale an image - correction

Kelvin Cheng KCheng at extracomm.com
Tue Jan 20 22:36:39 PST 2009


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 ?

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, 2.0, 2.0); 
        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/c4222876/attachment.html 


More information about the cairo mailing list