Thread overview | |||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
December 30, 2015 GTKD Cairo get pixel color | ||||
---|---|---|---|---|
| ||||
Hello, is there any way to get the pixel color of a single pixel by x and y coordinates of a context? |
December 30, 2015 Re: GTKD Cairo get pixel color | ||||
---|---|---|---|---|
| ||||
Posted in reply to TheDGuy | 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. |
January 01, 2016 Re: GTKD Cairo get pixel color | ||||
---|---|---|---|---|
| ||||
Posted in reply to Basile B. | 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'" |
January 01, 2016 Re: GTKD Cairo get pixel color | ||||
---|---|---|---|---|
| ||||
Posted in reply to TheDGuy | 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 |
January 01, 2016 Re: GTKD Cairo get pixel color | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Wey | On Friday, 1 January 2016 at 15:22:18 UTC, Mike Wey wrote:
> On 01/01/2016 01:37 PM, TheDGuy wrote:
>> [...]
>
> you would either cr.getTarget(); or cairo.ImageSurface.ImageSurface.create.
>
> I'm not sure how those would get you access to the pixel data.
Okay, thanks for your answer.
So which function do i call with "cr.getTarget()" and how can i get the rgb-values of a pixel from it?
|
January 01, 2016 Re: GTKD Cairo get pixel color | ||||
---|---|---|---|---|
| ||||
Posted in reply to Basile B. | 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. |
January 01, 2016 Re: GTKD Cairo get pixel color | ||||
---|---|---|---|---|
| ||||
Posted in reply to Basile B. | 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? |
January 01, 2016 Re: GTKD Cairo get pixel color | ||||
---|---|---|---|---|
| ||||
Posted in reply to TheDGuy | 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' 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 |
January 02, 2016 Re: GTKD Cairo get pixel color | ||||
---|---|---|---|---|
| ||||
Posted in reply to TheDGuy | 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 |
January 02, 2016 Re: GTKD Cairo get pixel color | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Wey | > ``` > 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. Thanks, that was the problem! Now i can read the buffer from a png image and save the buffer as a file: auto pngImage = ImageSurface.createFromPng("C:\\Users\\Standardbenutzer\\Desktop\\DSC00564-1.png"); auto buffer = pngImage.getData(); auto cS = ImageSurface.createForData(buffer, cairo_format_t.ARGB32,pngImage.getWidth(),pngImage.getHeight(),pngImage.getStride()); cS.writeToPng("test.png"); but how do i do that with my GTKD Context in my "drawCallback()" function? |
Copyright © 1999-2021 by the D Language Foundation