1
我正努力将二进制数据转换为gtk.gdk.pixbuf
。从二进制数据创建一个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: data length (90825) is less then required by the other parameters (865280)
我目前的解决方法是将二进制数据写入一个文件,然后从该文件中创建一个Pixbuf
。这只是感觉很不好。我正在从数据库读取二进制数据,所以我真的需要一个可以直接从缓冲区创建pixbuf的解决方案。
我不明白为什么它很容易,如果我只是从数据库中读取的BLOB
,并将其写入到一个文件 - 然后加载该文件作为一个pixbuf的,但很难从缓冲区直接去!
我在做什么错?
辉煌,谢谢 – jsj