[cairo] Rotation in cairo

Hung Nguyen Vu vuhung16plus+shape at gmail.com
Mon Aug 4 03:38:49 PDT 2008

Hello all,

How can I rotate a surface in cairo around it's center?
I've tried the following code but the output image( Flag-rotate.png) remains
the same as Flag.png. I expect a rotation of M_PI/2.

#include <cairo.h>
#include <math.h>
int main (int argc, char *argv[])

 int w, h;

  cairo_surface_t *image;
  cairo_t *cr;

  image = cairo_image_surface_create_from_png ("Flag.png");
  cr = cairo_create (image);

  w = cairo_image_surface_get_width (image);
  h = cairo_image_surface_get_height (image);
  cairo_translate (cr, w * 0.5, h * 0.5);
  cairo_rotate (cr, M_PI / 2.0);
  cairo_translate (cr, -w * 0.5, -h * 0.5);
  cairo_set_source_surface (cr, image, w*0.5, h*0.5);
  cairo_surface_write_to_png (image, "Flag-rotate.png");

  cairo_paint (cr);
  cairo_surface_destroy (image);

  return 0;


Best Regards,
Nguyen Hung Vu ( Nguyễn Vũ Hưng )
vuhung16plus{remove}@gmail.dot.com , YIM: vuhung16 , Skype: vuhung16dg
Japan through an eye of a gaijin:

More information about the cairo mailing list