Frage

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);
War es hilfreich?

Lösung 2

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

Andere Tipps

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);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top