[cairo] How to convert cairo content to gdk-bifbuf

Carl Worth cworth at cworth.org
Sat Jul 15 07:25:40 PDT 2006


On Fri, 14 Jul 2006 10:52:32 -0700, Li Li wrote:
> 
> My question is how to convert the cairo drawing context to
> gdk-pixbuf.

Why do you want to do this?

As far as I understand things, there should really be no compelling
reason to ever want to draw _to_ a GdkPixbuf. The GdkPixbuf stuff
comes with a lot of image loaders, so it is useful to use it to load
an image with it, and read _from_ the pixbuf, (and in that case
conversion can be done just once).

If there's some API somewhere that insists on accepting a GdkPixbuf,
then perhaps it just needs to be updated to accept a cairo surface
instead?

But, anyway, there should be conversion code again. I know that GDK
must have some because it does allow one to set a GdkPixbuf as a
source surface pattern in cairo, (gdk_cairo_set_source_pixbuf I
think?). That function must be doing conversion, (in the other
direction, but it should be reversible if you really want to do this).

Then a couple of comments on your code:


>    cairo_surface_t *cs= cairo_image_surface_create_for_data(data,
>             CAIRO_FORMAT_RGB24, width, height, 4*width);
> 
>    cairo_t *cr=cairo_create(cs);
> 
>    cairo_rectangle (cr, 0, 0, width, height);
> 
>    cairo_clip (cr);

This clip isn't helping you at all. It's clipping to the extents of
the surface which happens by default anyway, (cairo can't help
it---there's no way to draw outside a surface).

>    cr_convert_to_pixbuf(data, width, height, pixbuf);//do conversion

What is that function? It's clearly not a cairo nor a GTK+ function.

-Carl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20060715/1d380b9f/attachment.pgp


More information about the cairo mailing list