[cairo] Using gimp c file image

Dov Grobgeld dov.grobgeld at gmail.com
Thu Dec 17 04:37:29 PST 2009

You can use gdk_pixbuf and in your build system do:

gdk-pixbuf-csource --name=foo_inline foo.png > foo.i

And in your c-source do:

#include "foo.i"


GdkPixbuf* foo_pixbuf = gdk_pixbuf_new_from_inline(sizeof(foo_inline),

You can then create a image surface through:

    cairo_surface_t *surface = cairo_image_surface_create_for_data

gdk_pixbuf_get_has_alpha(foo_pixbuf) ? CAIRO_FORMAT_ARGB32 :

There is one problem though, which is that cairo and gdk pixbuf does not
agree on the order of R,G,B and alpha. So you will have to swap the data
before you do this. (Instead of gdk pixbuf you can use any image library,
e.g. libpng, opencv, FreeImage, etc.)

Another option if cairo has been compiled with PNG support, is to do:

cairo_surface_t * cairo_image_surface_create_from_png_stream
                  (cairo_read_func_t read_func,
                   void *closure);

You will then have to write a read_func instance that will provide data from
your baked png file.

Hope this helps.

Lycka till!

On Thu, Dec 17, 2009 at 11:05, gurnett at telia.com <gurnett at telia.com> wrote:

> I have an app that has a lot of png files. I've asked previously if it was
> possible to use embedded png images with cairo, but this did not seem
> possible.
> As I really want to bake all this images into the exe I was wondering if it
> is
> possible to use the gimp c file image format and use that instead of
> image=cairo_image_surface_create_from_png("image.png");
> Thanks
> Michael
> --
> cairo mailing list
> cairo at cairographics.org
> http://lists.cairographics.org/mailman/listinfo/cairo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.cairographics.org/archives/cairo/attachments/20091217/bc9b6d7d/attachment.htm 

More information about the cairo mailing list