[cairo] rotating GdkPixbuf with cairo

Dominic Lachowicz domlachowicz at gmail.com
Tue Apr 1 10:03:23 PDT 2008


You need to save your "srf" to a file. gdk_cairo_set_source_pixbuf()
makes a copy of the pixbuf's pixels. You can use
cairo_surface_write_to_png() to accomplish what you want to do.

http://www.cairographics.org/manual/cairo-PNG-Support.html#cairo-surface-write-to-png

Cheers,
Dom

On Tue, Apr 1, 2008 at 12:49 PM, LRN <lrn1986 at gmail.com> 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?
>  _______________________________________________
>  cairo mailing list
>  cairo at cairographics.org
>  http://lists.cairographics.org/mailman/listinfo/cairo
>



-- 
Counting bodies like sheep to the rhythm of the war drums.


More information about the cairo mailing list