[cairo] scaling an image
Uli Schlachter
psychon at znc.in
Sat Aug 12 11:45:19 UTC 2017
Hi,
On 11.08.2017 22:43, folkert wrote:
> I would like to scale an image.
> Is that something I could do with cairo? Because according to google
> cairo_scale does not resize the surface.
What kind of scaling exactly? The following (untested) code scales an
image to half the size (rounded down); does that help you?
cairo_surface_t *scale_to_half(cairo_surface_t *s, int orig_width, int
orig_height)
{
cairo_surface_t *result = cairo_surface_create_similar(s,
cairo_surface_get_content(s), orig_width/2, orig_height/2);
cairo_t *cr = cairo_create(result);
cairo_scale(cr, 0.5, 0.5);
cairo_set_source_surface(cr, s, 0, 0);
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
cairo_paint(cr);
cairo_destroy(cr);
return result;
}
Cheers,
Uli
--
Homophobia - The fear that another man will treat you the way you treat
women.
More information about the cairo
mailing list