0

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.

ChrA
  • 5
  • 4

1 Answers1

1

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.

Alexander Dmitriev
  • 2,483
  • 1
  • 15
  • 20
  • Thanks to the link provided by you I manage to include the pixbuf loader correctly. Works now perfectly fine without involving writing to hdd and reading back – ChrA Mar 10 '19 at 14:27