如何从流加载图像文件到gtk.gdk.Pixbuf?

时间:2021-05-08 19:00:26

I have a file picture.jpg, i'm reading it to memory

我有一个文件picture.jpg,我正在读它记忆

f = open('picture.jpg', 'rb')
pic = f.read()
f.close()

How can I convert pic to gtk.gdk.Pixbuf? I know that there is gdk_pixbuf_new_from_stream() but it appears to be missing from pyGTK :/

如何将pic转换为gtk.gdk.Pixbuf?我知道有gdk_pixbuf_new_from_stream()但似乎缺少pyGTK:/

1 个解决方案

#1


7  

You can use a Pixbuf loader:

您可以使用Pixbuf加载器:

loader = gtk.gdk.PixbufLoader('jpeg')
loader.write(pic)
loader.close()

pixbuf = loader.get_pixbuf()

#1


7  

You can use a Pixbuf loader:

您可以使用Pixbuf加载器:

loader = gtk.gdk.PixbufLoader('jpeg')
loader.write(pic)
loader.close()

pixbuf = loader.get_pixbuf()