[pygtk] image manipulation

Edward Catmur ed at catmur.co.uk
Fri Sep 8 23:04:36 WST 2006

On Fri, 2006-09-08 at 11:44 -0300, Rodrigo Renie Braga wrote:
> Hello list
> I would like to know if there is a (easy) way to grab rgb information
> of an image and then modify it with new rgb information... i'm making
> an application to apply different set of filters on an image, and i
> need to, basicly: 
> - load an image
> - be able to grab the rgb information of a certain pixel
> - make a new image with a different rgb (calculated by my algorithm)
> - show that image to the user an then save it to a file
> what is the best way to work with rgb and image using pygtk? 

You *can* access the pixel data of a GdkPixbuf with
gtk.gdk.Pixbuf.get_pixels(), but that's very slow and painful. 

Better is to ensure that PyGtk is compiled with Numeric, and use
gtk.gdk.Pixbuf.get_pixels_array() to get the pixel data (in RGB[A]) as a
Numeric array. You can then apply array transforms to the array using
Numeric. You then recreate a GdkPixbuf from the transformed array with
gtk.gdk.pixbuf_new_from_array(), and save it with gtk.gdk.Pixbuf.save().


More information about the pygtk mailing list