teales
Joined: 21 May 2007 Posts: 24 Location: Bangalore
|
Posted: Fri Sep 02, 2011 12:53 pm Post subject: From an ImageSurface to a Pixbuf |
|
|
The GTK documentation is a bit cryptic around this point. The following might help:
extern(C) cairo_status_t imgWriteFunc(void* closure,
uchar* data, uint len)
{
PixbufLoader pbl = cast(PixbufLoader) closure;
char[] t;
t.length = len;
t[] = cast(char[]) data[0..len];
int rv = pbl.write(t);
return rv? cairo_status_t.SUCCESS: cairo_status_t.WRITE_ERROR;
}
Pixbuf getPixbuf()
{
ImageSurface isf = ImageSurface.create(cairo_format_t.RGB24,
width, height);
Context isc = Context.create(isf);
render(isc);
PixbufLoader pbl = new PixbufLoader();
isf.writeToPngStream (&imgWriteFunc, cast(void*) pbl);
pbl.close();
return pbl.getPixbuf();
}
This is hacked out of my code, and not tested, but it should show the way. |
|