Reputation: 5
I've been searching quite some time but did not succeed. In my little python3.6 application I am reading an image from a sqlite database, writing it to a png file
cur = self.con.cursor()
cur.execute('SELECT image FROM image WHERE id IS ?', str(uid))
image = cur.fetchone()[0]
fout = open('temp.png', 'wb')
fout.write(image)
fout.close()
only to read it back in to be displayed using
self.preview.set_from_file('temp.png')
where preview is a GtkImage created with
self.preview = builder.get_object('preview')
Is there a way to skip the writing to disk? I would much rather like to display the image straight from the db.
Thanks in advance.
Upvotes: 0
Views: 84
Reputation: 2525
Gtk.Image
has two methods which may be interesting. It's set_from_pixbuf and set_from_surface.
If you choose surface
-way, you may need to install pycairo as it's not provided with python3-gi
. To make a surface you fetch your image and use create_for_data.
Probably, pixbuf
-way is simpler. Take a look at this answer to see, how GdkPixbufLoader
creates GdkPixbuf from data.
Upvotes: 1