GTKD Cairo get pixel color

Mike Wey via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 1 07:22:18 PST 2016


On 01/01/2016 01:37 PM, TheDGuy wrote:
> On Wednesday, 30 December 2015 at 23:20:23 UTC, Basile B. wrote:
>> On Wednesday, 30 December 2015 at 20:44:44 UTC, TheDGuy wrote:
>>> Hello,
>>>
>>> is there any way to get the pixel color of a single pixel by x and y
>>> coordinates of a context?
>>
>> render to a png back buffer.
>>
>> see cairo_image_surface_create_for_data
>>
>> then you'll be able to access the data and, at the same time, to blit
>> your buffer to screen.
>
> Thanks for your answer. But how do i access the function via the context?
>
> It does not work like this:
>
> class DW:DrawingArea{
>      this(){
>          addOnDraw(&drawCallback);
>      }
>      bool drawCallback(Scoped!Context cr, Widget widget){
>          char[] c = new char[](256*256);
>          auto val =
> cr.cairo_image_surface_create_for_data(c,cairo_format_t.CAIRO_FORMAT_ARGB32,
> 256,256,
> cairo.format_stride_for_width(cairo_format_t.CAIRO_FORMAT_ARGB32,256));
>          return true;
>      }
> }
> "no property 'cairo_image_surface_create_for_data' for type 'Scoped'"

you would either cr.getTarget(); or cairo.ImageSurface.ImageSurface.create.

I'm not sure how those would get you access to the pixel data.

-- 
Mike Wey


More information about the Digitalmars-d-learn mailing list