[cairo] antialias for images?

Peter Goetz peter.gtz2 at gmail.com
Sun Oct 14 16:24:35 PDT 2007

Hi all,
I'm trying to scale and rotate an image and then put it on a surface
using paint as it is shown in one of the examples.
However the scaling is not done by something like a bicubic filter but
just by a linear one, so the picture looks very noisy (see screenshot
attached) and has a staircase effect on the edges.
Is there a way to make it look smooth? Some antialias for images? I
haven't found something in the mail-archives.
Thanks for your help!


#include <cairo.h>

int main (int argc, char *argv[])
       cairo_surface_t *surface;
       cairo_t *cr;
       int w, h;
       cairo_surface_t *image;

       surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 256, 256);
       cr = cairo_create (surface);

       double M_PI=3.14;

       image = cairo_image_surface_create_from_png ("test.png");
       w = cairo_image_surface_get_width (image);
       h = cairo_image_surface_get_height (image);

       cairo_translate (cr, 128.0, 128.0);
       cairo_rotate (cr, 20* M_PI/180);
       cairo_scale  (cr, 256.0/w, 256.0/h);
       cairo_translate (cr, -0.5*w, -0.5*h);

       cairo_set_source_surface (cr, image, 0, 0);
       cairo_paint (cr);

       cairo_surface_destroy (image);

       cairo_destroy (cr);
       cairo_surface_write_to_png (surface, "output.png");
       cairo_surface_destroy (surface);

       return 0;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: output.png
Type: image/png
Size: 47960 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20071015/cb14c4d6/attachment-0001.png 

More information about the cairo mailing list