GTKD Cairo get pixel color

Mike Wey via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jan 2 01:49:18 PST 2016


On 01/02/2016 12:32 AM, TheDGuy wrote:
> On Friday, 1 January 2016 at 22:00:04 UTC, TheDGuy wrote:
>> On Friday, 1 January 2016 at 19:32:40 UTC, Basile B. 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.
>>>
>>>
>>> Actually I was thinking to a user defined buffer type:
>>>
>>> struct SurfaceBuffer
>>> {
>>>     void* data; // used as param to create the surface
>>>     Rgba[] opIndex(size_t index);
>>>     Rgba[][] scanline();
>>> }
>>>
>>> that you would pass as data in cairo_image_surface_create_for_data().
>>>
>>> But gtk certainly has pitcure classes with the typical scanline
>>> method and that you could use in cairo_image_surface_create_for_data.
>>
>> Ahm, i am not quite sure if you and [Mike Wey] talk about the same
>> thing. And i posted the error message in my last post when i try to
>> call "cairo_image_surface_create_for_data". I still don't know where i
>> am able to call the function?
>
> I took a look into the source code of cairo and in the
> "ImageSurface.d"-file there is a function called "createForData" but if
> i try to use it like this:
>
> cairo.ImageSurface.createForData(c,cairo.FORMAT_ARGB32,256,256,256*4);
>
> i get: "undefined identifier 'createForData' in module 'cairo.ImageSurface'

```
import cairo.ImageSurface;
ImageSurface.createForData(c,cairo.FORMAT_ARGB32,256,256,256*4);
```

You need to import the ImageSurface module, and the createForData 
function is in the ImageSurface class which is in the cairo.ImageSurface 
module.


> That is just one example of my experience using D:
>
> some things are easy to understand but in other cases: even if you think
> it should work and you can proof it, it just doesn't or you have to do
> it in a really inconvenient way. I am getting frustrated

-- 
Mike Wey


More information about the Digitalmars-d-learn mailing list