Python 从二进制数据创建gtk.gdk.Pixbuf

Python 从二进制数据创建gtk.gdk.Pixbuf,python,gtk,gdk,gdkpixbuf,Python,Gtk,Gdk,Gdkpixbuf,我正在努力将二进制数据放入gtk.gdk.pixbuf 这应该说明我的问题: file = open("image.jpg", "rb") //Ultimately this is going to come from a BLOB binary = f.read() //I created a pixbuf directly from the jpg //and took the rowstride values &c. from that pixbuf = gtk.gdk.pixb

我正在努力将二进制数据放入
gtk.gdk.pixbuf

这应该说明我的问题:

file = open("image.jpg", "rb")
//Ultimately this is going to come from a BLOB
binary = f.read()
//I created a pixbuf directly from the jpg 
//and took the rowstride values &c. from that
pixbuf = gtk.gdk.pixbuf_new_from_data(
    binary, gtk.gdk.COLORSPACE_RGB, False, 8 , 450, 640, 1352)
这在以下情况下失败:

ValueError:数据长度(90825)小于其他参数(865280)所需的长度

我目前的解决方法是将二进制数据写入一个文件,然后从该文件创建一个
Pixbuf
。那感觉真烦人。我正在从数据库读取二进制数据,所以我真的需要一个可以直接从缓冲区创建pixbuf的解决方案

我不明白为什么从数据库中读取
BLOB
并将其写入文件很容易,然后将文件作为pixbuf加载,但直接从缓冲区加载却很难


我做错了什么?

您试图用一种方法处理jpg数据

如果要处理JPG,请使用此格式的加载程序,建议如下:


现在
pixbuf
包含了您需要的内容。您的解决方法。

您正在尝试使用一种方法处理jpg数据

如果要处理JPG,请使用此格式的加载程序,建议如下:

现在
pixbuf
包含了您需要的内容。你的变通方法

file = open("image.jpg", "rb")
binary = file.read()
loader = gtk.gdk.PixbufLoader("jpeg")
loader.write(binary)
loader.close()
pixbuf = loader.get_pixbuf()