Timo List wrote: > My program uses the SQLite database. The database holds some > information about persons and I want to add a picture for each person. > Not the path to the file, but the actual image so that the image also > works if the file is deleted on the harddisk. > > I can save the image in a BLOB column as: > imgfile = open('/path/to/image.png') > db.save_image(imgfile.read()) > > Works fine as far as I see. (Maybe any comments on this?) > > Retrieving also works, but I see no possibility to show this image in > a gtk.Image widget. I can't seem to find anything related to this on > the net, maybe someone reading this has done this before? One possibility is to save the image as a compressed in-line image in the db and create a pixbuf from the in-line data after it's retrieved and decompressed. Here's some code to create an in-line image and compress it:
import struct, bz2 ... # pb is a pixbuf containing the image to be in-lined pix = pb.get_pixels() inline_img = 'GdkP'+struct.pack('!iBBHiii',len(pix)+24,1,1,pb.get_has_alpha()+1, pb.get_rowstride(),pb.get_width(),pb.get_height())+pix bz2_inline_img = bz2.compress(inline_img) # save bz2_inline_ob in the db To use the compressed in-line image use something like: # the compressed in-line image is in bz2_inline_img inline_img = bz2.decompress(bz2_inline_img) pb = gtk.gdk.pixbuf_new_from_inline(-1, inline_img, False) Copy the pixels if you are going to delete the inline_img string. Then you can use the pixbuf to create your image. John _______________________________________________ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/