PDA

View Full Version : python pixbuf/image to string



giuspen
November 24th, 2009, 10:36 AM
hi,
I need to encode a pygtk pixbuf (or an image) into a string, I found that it is possible to save a pixbuf into a file and then encode base64, but is there a faster way to go directly from pixbuf to string or I have to go through saving a file to disk and then encode it?
Thanks in advance.

kripkenstein
November 24th, 2009, 10:41 AM
This should work:


pixel_string = pb.get_pixels()

assuming pb is a PyGTK pixbuf.

giuspen
November 24th, 2009, 10:47 AM
This should work:


pixel_string = pb.get_pixels()

assuming pb is a PyGTK pixbuf.

but in the gtk.gdk.Pixbuf documentation I can't find how to build again the pixbuf from the pixel_string

kripkenstein
November 24th, 2009, 10:57 AM
but in the gtk.gdk.Pixbuf documentation I can't find how to build again the pixbuf from the pixel_string

For that direction, you can use gtk.gdk.pixbuf_new_from_data (http://www.pygtk.org/docs/pygtk/class-gdkpixbuf.html#function-gdk--pixbuf-new-from-data).

giuspen
November 24th, 2009, 11:02 AM
For that direction, you can use gtk.gdk.pixbuf_new_from_data (http://www.pygtk.org/docs/pygtk/class-gdkpixbuf.html#function-gdk--pixbuf-new-from-data).

thanks