1

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

2 Answers2

1

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.

theGtknerd
  • 3,647
  • 1
  • 13
  • 34
  • Thanks! And also for the second question, if I want to make the image bigger, is it possible for make the container's size fixed, so that when image gets bigger, the part exceeds the container does not show in the container. (Cuz usually the container just get larger along with its image. – Andrew Shao Apr 05 '18 at 02:35
  • A [scrolled window](https://developer.gnome.org/gnome-devel-demos/stable/scrolledwindow.c.html.en), maybe? – theGtknerd Apr 05 '18 at 10:30
  • Please provide a use case and code for your request. Without knowing what you are doing, and what you tried, it is hard to recommend a solution. – theGtknerd Apr 05 '18 at 10:31
  • Okay Sorry about the confusion. For example, I had a 200 * 200 window, add a container, add a 100* 100 image to the container, if we move around the image, say we move it towards right, when image hits the border of the window, the window is going to grow alongwith when I move the image more. I want to prevent the container from resizing. I wonder if I made it clear... – Andrew Shao Apr 06 '18 at 01:05
  • Oh it does look like scrolled window is a good solution. Ill try that! Thanks! – Andrew Shao Apr 06 '18 at 01:14
0

So I tried something other than scrolled view, I was using gtk_fixed, whose size is going to increment if we move a widget outside the window.

And I switched to gtk_layout later(which includes the functionality that gtk_fixed had), and set the adjustment, to have the size of the layout fixed.

Sorry about the confusion again in previous answer!