[cairo] Get pixeldata from image
Lobais
lobais at gmail.com
Sun Nov 19 13:30:27 PST 2006
Thanks a lot.
Now I just have to ask how I save the changes? It seems like
cairo_image_surface_get_data only returns a copy of the data.
I've tried to use the create_for_data function to create a new surface from
the data, and save it using write_to_png, but it seems like it creates a few
problems for some pixel, that get totally white..
I'm using pycairo, but guess it should be working the same way:
surface = cairo.ImageSurface.create_from_png(test.png)
buffer = surface.get_data_as_rgba()
surface = cairo.ImageSurface.create_for_data (
buffer, cairo.FORMAT_ARGB32,
surface.get_width(), surface.get_height(),
surface.get_stride())
surface.write_to_png("test_out.png")
On 11/19/06, Andrew McRae <amcrae at employees.org> wrote:
>
> On Sun, 2006-11-19 at 12:57 +0100, Lobais wrote:
> > Hi, it is possible to get the image data of an image, such that one
> > would be able to e.g. get red, green and blue from pixel 8 row 4?
> >
> > --
> > Best Regards, Thomas
>
> The easiest way (from what I know) is to use
> cairo_image_surface_get_data and friends. As long
> as you know it's a RGB or ARGB format (you can check
> with cairo_image_surface_get_format), it's
> going to be a 32 bit pixel element image.
>
> Here's a sample code snippet:
>
> unsigned char *data = cairo_image_surface_get_data(surface);
> int stride = cairo_image_surface_get_stride(surface);
>
> uint32_t *pixelptr;
> ...
> pixelptr = (uint32_t *)(data + 4 * stride); // row 4
> my_pixel = pixel[8]; // pixel 8
> red = (pixel[8] >> 16) & 0xFF;
>
> Cheers,
> AMc
>
>
--
Mvh. Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/cairo/attachments/20061119/b699258c/attachment.html
More information about the cairo
mailing list