Sunday, September 25, 2011

Drawing a pixbuf with cairo

I wanted to be able to add an image to a drawing area and draw onto it with cairo. The standard way to draw an image with cairo is to use a surface, created for example with cairo_image_surface_create_from_png. This seems to limit you to various image formats, in my case the images I want to use are in a non-trivial format (BAS image plate scans) which I can get into pixbuf format. I'm not sure if this is the best solution, but I used
pixbuf = gdk_pixbuf_scale_simple (pixbuf, GDK_INTERP_BILINEAR);

gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);

cairo_rectangle (cr, 0, 0, width, height);

cairo_fill (cr);
where width and height are for the drawing area.

No comments:

Post a Comment