It turns out that the code above is exactly correct... I just wasn't drawing anything to the surface. Works great!
Cairo.ImageSurface to Gdk.Pixbuf? [closed]
문제
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);
해결책 2
다른 팁
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);
제휴하지 않습니다 StackOverflow