PyGTK: creating a pixbuf from image data

John Hunter jdhunter at ace.bsd.uchicago.edu
Mon Mar 15 12:57:55 EST 2004


>>>>> "Edwin" == Edwin Young <edwin at localhost.localdomain> writes:

    Edwin> Hi,

    Edwin> I'm writing a fractal-generating program in a mixture of C
    Edwin> and Python. Python handles all the GUI parts using
    Edwin> PyGTK. After finishing the calculations, I have a buffer
    Edwin> containing the RGB data of the image. I can display this
    Edwin> fine on screen using draw_rgb_image. Now I need to save the
    Edwin> image data into a file. gtk.gdk.Pixbuf.save() 

gtk.gdk.Pixbuf does have a save method

http://www.gnome.org/~james/pygtk-docs/class-gdkpixbuf.html

Alternatively, if you have a pixbuf instance that contains your image
data, you can access the data as an RGBA array with

  # pb is a gtk.gdk.Pixbuf
  pa = pb.get_pixels_array()  #pygtk 2.2 and

or 
  
  pa = pb.pixel_array   # pygtk-2.0

You can then access the rgba components, eg

    pa[:,:,0]  # red
    pa[:,:,1]  # green
    pa[:,:,2]  # blue
    pa[:,:,3]  # alpha

and write them to a file anyway you want.

Or am I not understanding you?

JDH




More information about the Python-list mailing list