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 :(

Reply via email to