[cairo] Get pixeldata from image

Andrew McRae amcrae at employees.org
Sun Nov 19 13:44:02 PST 2006


On Sun, 2006-11-19 at 22:30 +0100, Lobais wrote:
> 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")

I am no python coder, so I'm not sure what your intent is
here. cairo_image_surface_get_data doesn't copy
the image data, just returns a pointer to the image buffer.
At least, for the C version of the library it does.
I'm not sure what the python equivalent is. I wouldn't
have thought you needed to create a new surface
using the buffer from the original one, just use the
surface that was created from the file.
Perhaps a python developer could help more...
Cheers,
AMc



More information about the cairo mailing list