Search code examples
c++gtkgtk3opencv3.0

Gtk 3 when widget is too large


I am kind of new to gtk 3.0 +, And I was wondering how do people deal with the case when the image size is too big.

  1. Is it possible to have a fixed size frame to display image(as far as I know, seems like the container size will change depend on widget size it holds, gtk_overlay seems to be possible, but I m not sure if there is other ways of doing this

  2. If step 1 is possible, when the image get too large, what is the idea of, under the fixed size area, when we move around the image, we could see different part of the image(other part that exceeds the area is not showing


Solution

  • It is pretty easy when you know how. In C:

    GdkPixbuf *pixbuf;
    GtkWidget *preview_image;
    
    preview_image = gtk_image_new ();
    pixbuf = gdk_pixbuf_new_from_file_at_scale (file_uri, 
                                                128, 
                                                128, 
                                                TRUE, NULL);
    gtk_image_set_from_pixbuf (GTK_IMAGE(preview_image), pixbuf);
    

    the pixbuf docs and the image docs

    Basically, you can't put an image in any type of scrolling 'window' directly from a file. Instead, load the file into a pixbuf, and the pixbuf into the image and all sizing should automatically take care of itself.