Pickeling Pixbuf Pixel Arrays

After lots of googling, I finally figured how to pickle a gtk.gdk.Pixbuf‘s pixel array. I was looking for a way to pickle a Pixbuf’s image data into a file easily. The original C API provides a dedicated interface for that, unfortunately the pygtk developers seem to believe that there is no need to support it with the Python binding. So I tried to get access to the image data through the Pixbuf’s pixel_array property. Unfortunately this will yield an unpickleable standard Python array instance if you import gtk only. If you also import Numeric (assuming you have it available) a call to get_pixel_array() will yield a Numeric array instance instead and Numeric arrays are very well pickleable.

Hopefully this will speed up other people’s googling.