Reputation: 549
I have a cairo_surface_t
image surface that contains an arbitrary sized icon, and would like to scale it so that it fits into a window that I am drawing into. The window has a cairo_t
drawing context that can be painted into. Example code is below
cairo_surface_t *image;
double scale = cairo_image_get_surface_height(image) / window->height;
// Scale here
cairo_set_source_surface(cairo, image, 0, 0);
cairo_paint(cairo);
Upvotes: 2
Views: 6456
Reputation: 47
You can use the cairo_scale
API.
Example: cairo_scale(cairo, scale_width, scale_height);
I will do this like below:
cairo_surface_t *surf = cairo_image_surface_create_for_data(resize_image_data, CAIRO_FORMAT_RGB24, resize_image_width, resize_image_height, image_stride);
cairo_set_source_surface(cr, surf, 0, 0);
cairo_paint(cr);
Upvotes: 3