jsj*_*jsj 1 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.pixbuf_new_from_data(
binary, gtk.gdk.COLORSPACE_RGB, False, 8 , 450, 640, 1352)
Run Code Online (Sandbox Code Playgroud)
这失败了:
ValueError: data length (90825) is less then required by the other parameters (865280)
我目前的解决方法是将二进制数据写入文件,然后Pixbuf
从该文件创建.这只是感觉很hacky.我正在从数据库中读取二进制数据,所以我真的需要一个可以直接从缓冲区创建pixbuf的解决方案.
我不明白为什么如果我只是BLOB
从数据库中读取并将其写入文件 - 然后将文件作为pixbuf加载,这很容易,但更难直接从缓冲区!
我究竟做错了什么?
如果你要处理的JPG文件,使用加载这个格式,建议在这里:
file = open("image.jpg", "rb")
binary = file.read()
loader = gtk.gdk.PixbufLoader("jpeg")
loader.write(binary)
loader.close()
pixbuf = loader.get_pixbuf()
Run Code Online (Sandbox Code Playgroud)
现在pixbuf
包含,你需要什么.您的解决方法自动使用这样的加载器.
归档时间: |
|
查看次数: |
1685 次 |
最近记录: |