On 01/04/2016 09:13 PM, TheDGuy wrote:
On Monday, 4 January 2016 at 19:27:48 UTC, Mike Wey wrote:
I think you are looking for something like this.
Context.getTarget will get you the surface the Context is drawing to,
this most likely isn't a ImageSurface.
So you will need to create an pixbuf from the returned surface, with
the Pixbuf you can then get the raw pixel data using
getPixelsWithLength().
```
import gdk.Pixbuf;
bool drawCallback(Scoped!Context cr, Widget widget)
{
GtkAllocation size;
Pixbuf surafce;
getAllocation(size);
//Draw something;
surface = getFromSurface(cr.getTarget(), 0, 0, size.width,
size.height);
ubyte[] data = cast(ubyte[])surface.getPixelsWithLength();
//Do somthing with data.
return true;
}
```
getPixelsWithLength has the wrong return type, which will probably be
fixed some time.
Thank you very much! But surface.getPixelsWithLength() only gives me an
array with 16 fields (with a 256x256 DrawingArea)?
I also tried to save the Pixbuf with:
string[] options = ["quality"];
string[] opval = ["100"];
surface.savev("C:\\Users\\Standardbenutzer\\Desktop\test.jpeg", "jpeg",
options, opval);
but i found absolutely NOTHING about the options or the option values i
have to set, therefore i get an invalid argument exception :(
I don't have any issues with either getPixelsWithLength and savev.
for the savev call there is an missing \ just before test.jpg, but that
might be a copy and paste error?
For the options that are available for savev the documentation of
GDK-PixBuff lists the few available options.
https://developer.gnome.org/gdk-pixbuf/unstable/gdk-pixbuf-File-saving.html#gdk-pixbuf-save
Although i'm on Linux so that might make an difference.
--
Mike Wey