-
Hi all, I'm using pillow to manipulate RGBA images; I'd like to incorporate them into the gtk4 front-end and I can't find an elegant way to transfer data between PIL.Image and gtk.Image/gtk.Picture. I see that pillow already has QT and TK plugins but none for GTK. Are there any plans (or any known workarounds) to make the two exchange data? |
Beta Was this translation helpful? Give feedback.
Answered by
radarhere
Feb 13, 2022
Replies: 1 comment 1 reply
-
There is no active plan for such functionality, no. Searching, I found https://gitlab.gnome.org/GNOME/pygobject/-/issues/225 from PIL import Image
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GdkPixbuf, GLib
topgtkwindow = Gtk.Window( title = "TEST" )
topgtkwindow.connect( "destroy", Gtk.main_quit )
gtkimage = Gtk.Image()
topgtkwindow.add( gtkimage )
topgtkwindow.show_all()
pillowimage = Image.new( "RGB", (800,600) )
glibbytes = GLib.Bytes.new( pillowimage.tobytes() )
gdkpixbuf = GdkPixbuf.Pixbuf.new_from_data( glibbytes.get_data(), GdkPixbuf.Colorspace.RGB, False, 8, pillowimage.width, pillowimage.height, len( pillowimage.getbands() )*pillowimage.width, None, None )
gtkimage.set_from_pixbuf( gdkpixbuf ) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
radarhere
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is no active plan for such functionality, no.
Searching, I found https://gitlab.gnome.org/GNOME/pygobject/-/issues/225