Thanks a lot.<br>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.<br>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..
<br><br>I'm using pycairo, but guess it should be working the same way:<br><br>surface = cairo.ImageSurface.create_from_png(test.png)<br>buffer = surface.get_data_as_rgba()<br>surface = cairo.ImageSurface.create_for_data (
<br> buffer, cairo.FORMAT_ARGB32,<br> surface.get_width(), surface.get_height(),<br> surface.get_stride())<br>surface.write_to_png("test_out.png")<br><br><div><span class="gmail_quote">
On 11/19/06, <b class="gmail_sendername">Andrew McRae</b> <<a href="mailto:amcrae@employees.org">amcrae@employees.org</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On Sun, 2006-11-19 at 12:57 +0100, Lobais wrote:<br>> Hi, it is possible to get the image data of an image, such that one<br>> would be able to e.g. get red, green and blue from pixel 8 row 4?<br>><br>> --<br>
> Best Regards, Thomas<br><br>The easiest way (from what I know) is to use<br>cairo_image_surface_get_data and friends. As long<br>as you know it's a RGB or ARGB format (you can check<br>with cairo_image_surface_get_format), it's
<br>going to be a 32 bit pixel element image.<br><br>Here's a sample code snippet:<br><br> unsigned char *data = cairo_image_surface_get_data(surface);<br> int stride = cairo_image_surface_get_stride(surface);<br><br> uint32_t *pixelptr;
<br> ...<br> pixelptr = (uint32_t *)(data + 4 * stride); // row 4<br> my_pixel = pixel[8]; // pixel 8<br> red = (pixel[8] >> 16) & 0xFF;<br><br>Cheers,<br>AMc<br><br></blockquote>
</div><br><br clear="all"><br>-- <br>Mvh. Thomas