[cairo] Re: Get pixeldata from image

Lobais lobais at gmail.com
Mon Nov 20 11:55:58 PST 2006


Okay, it seems that pycairo hasn't yet implemented all nessesery methods. I
found another way though, which I think is useable for the time being.

surface = cairo.ImageSurface.create_from_png(imagepath)
buffer = surface.get_data_as_rgba()

data = array ('c', 'a' * surface.get_width() * surface.get_height() * 4)
surf = cairo.ImageSurface.create_for_data (data, cairo.FORMAT_ARGB32,
        surface.get_width(), surface.get_height(), surface.get_stride())
ctx = cairo.Context (surf)
ctx.rectangle (0, 0, surface.get_width(), surface.get_height())
ctx.set_source_surface(surface, 0, 0)
ctx.fill()

# Here the data array can be modified. e.g. using an algorithm like gimp
overlay mode.

self.surface = cairo.ImageSurface.create_for_data (
            data, cairo.FORMAT_ARGB32,
            surface.get_width(), surface.get_height(),
            surface.get_stride())

On 11/19/06, Lobais <lobais at gmail.com> 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




-- 
Mvh. Thomas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/cairo/attachments/20061120/2bb9e654/attachment.html


More information about the cairo mailing list