How to get pixbuf from image in GTK4?

Calling gtk::Image::set_from_pixbuf ends up creating a gdk::Texture from the pixbuf and then calls gtk::Image::set_paintable for you. In other words, you could get the paintable using gtk::Image::paintable() and downcast it to a gdk::Texture with

let texture = image.paintable().unwrap().downcast::<gdk::Texture>().unwrap();

Then it depends on whatever you were using the pixbuf for.

1 Like