Re: scaling an image

Uli Schlachter <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
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.
-- 
cairo mailing list
[email protected]
https://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.