GTKD Cairo get pixel color

Mike Wey via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jan 4 11:27:48 PST 2016


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.

-- 
Mike Wey


More information about the Digitalmars-d-learn mailing list