3

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);
liberforce
  • 11,189
  • 37
  • 48
Doug Blank
  • 2,031
  • 18
  • 36

2 Answers2

7

If you are using Gdk 3, you're in luck as this should work:

my_pixbuf = Gdk.pixbuf_get_from_surface (surface, x, y, w, h);
Jussi Kukkonen
  • 13,857
  • 1
  • 37
  • 54
2

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

Doug Blank
  • 2,031
  • 18
  • 36