转换PIL GdkPixbuf

Pla*_*aoo 5 python pygobject python-imaging-library gdkpixbuf

如何在pixbuf中转换PIL图像?我试图改变许多例子,但没有解决方案

import array
from gi.repository import GdkPixbuf

def image2pixbuf(self,im):
    arr = array.array('B', im.tostring())
    height, width = im.size
    return GdkPixbuf.Pixbuf.new_from_data(arr, GdkPixbuf.Colorspace.RGB,
                                      True, 8, width, height, width * 4)
Run Code Online (Sandbox Code Playgroud)

错误

TypeError: new_from_data () takes Exactly 9 arguments (7 given)
Run Code Online (Sandbox Code Playgroud)

我使用Pygobject https://live.gnome.org/PyGObject

Fro*_*oyo 1

我在Gtk3中也遇到了同样的问题。GdkPixbuf.PixbufDestroyNotify - NotImplementedError - python gtk3

好像有bug。我已经举报了。https://bugzilla.gnome.org/show_bug.cgi?id=674691

GTk3有这个bug。但你仍然可以在 Gtk2 中做到这一点。