How to resize image in gtk(rust)?

Hi,
I want to create preview of images, but I don’t know how to resize them with no aspect change.
I don’t see in https://developer.gnome.org/gtk3/stable/GtkImage.html any info how to do it.

For now I only load image with set_from_file function

I partially implemented it here:

I’m using image crate to load image, next I resize them to specific size, save them to .cache folder and at the end I load them from GTK.

This maybe not looks too optimal, but works really fast in most situation

Instead of temporary files you could also go via GdkPixbuf, or even use that for rescaling. The gdk_pixbuf crate provides bindings for that (loading files, rescaling, etc. or just creating one from in-memory RGB), and you can create a new gtk::Image from a pixbuf.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.