[cairo] Get pixeldata from image
Steve Chaplin
stevech1097 at yahoo.com.au
Mon Nov 20 04:08:59 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")
cairo_image_surface_get_data () returns a pointer to the image data of
the surface (not a copy).
cairo.ImageSurface.get_data_as_rgba() takes a cairo.FORMAT_ARGB32
surface and returns the data as rgba. It does not return the original
data because the original data is not in rgba format. It converts ARGB32
data to rgba. It was created so the data from a pycairo ImageSurface
could be read into the Python Image Library (since PIL does not support
ARGB32).
The current release of pycairo does not have a
cairo.ImageSurface.get_data() function. In CVS there is a
cairo.ImageSurface.get_data() which I added today. So if you want to
install using CVS you can test the new function.
See test/isurface_get_data.py for a test script which demonstrates the
new function.
Steve
Send instant messages to your online friends http://au.messenger.yahoo.com
More information about the cairo
mailing list