[cairo] rotating GdkPixbuf with cairo

LRN lrn1986 at gmail.com
Tue Apr 1 11:15:39 PDT 2008


LRN wrote:
> I want to load image from file into pixbuf, apply some cairo 
> transformations to it (for example - cairo_rotate) and then save it 
> back into file. Is it possible to use cairo in that way, or 
> cairo_rotate works only on vector objects?
> I tried this:
>
> GdkPixbuf *pbuf = gdk_pixbuf_new_from_file("g.png",NULL);
> int width = gdk_pixbuf_get_width(pbuf);
> int height = gdk_pixbuf_get_height(pbuf);
> cairo_surface_t *srf = 
> cairo_image_surface_create(CAIRO_FORMAT_RGB24,width,height);
> cairo_t *cr = cairo_create(srf);
> gdk_cairo_set_source_pixbuf(cr, pbuf, 0, 0);
> cairo_translate(cr,width,0);
> cairo_rotate(cr,M_PI/4);
> cairo_paint(cr);
> cairo_destroy(cr);
> gdk_pixbuf_save(pbuf,"g_rotated.png","png",NULL);
>
> but resulting file is the same as source file. Did i missed something?
>
>
Found the error. Shame on me...gdk_cairo_set_source_pixbuf() should be 
called AFTER translation and rotation is performed, just before the 
cairo_paint().


More information about the cairo mailing list