gtkcairogtk2gdkpixbuf

Cairo.ImageSurface to Gdk.Pixbuf?


Attempting to create a Pixbuf from an ImageSurface, but all I get are black pixels. Any ideas?

Cairo.ImageSurface surface = mysurface;
int w = surface.Width;
int h = surface.Height;
Gdk.Pixmap pixmap = new Gdk.Pixmap(null, w, h, 24);
using (Cairo.Context cr = Gdk.CairoHelper.Create(pixmap)) {
     cr.Operator = Cairo.Operator.Source;
     cr.SetSource(surface);
     cr.Paint();
}
_pixbuf = Gdk.Pixbuf.FromDrawable(pixmap, Gdk.Colormap.System, 0, 0, 0, 0, w, h);

Solution

  • It turns out that the code above is exactly correct... I just wasn't drawing anything to the surface. Works great!