Results 1 to 3 of 3

Thread: Gtk::Image resizing

  1. #1
    Join Date
    Aug 2005
    Beans
    41
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Angry Gtk::Image resizing

    Hi folks,

    I am writing my first programme with gtk and as part of it, I have a Gtk::Image which is loaded as the user clicks on a TreeView item.

    Loading the image is fine, but instead of fitting the bitmap to the size of the Gtk::Image, the Gtk::Image is expanded to fit the bitmap. I've been trying for about four hours to get the bitmap to automatically resize to the Gtk::Image. I can hardly believe that something so simple is so difficult.

    I have given up on the automatic resizing, and tried to load the bitmap to a Gdk::Pixbuf, resize it manually and then load the Gtk::Image with the Gdk::Pixbuf, but the resizing just doesn't work. Here's my code:

    Code:
    Glib::RefPtr<Gdk::Pixbuf> temp = Gdk::Pixbuf::create_from_file(row[in_files.fullname]);
    temp->scale_simple(750, 600, Gdk::INTERP_BILINEAR);
    img_scrshot.set(temp);
    Do any of you understand why the Pixbuf isn't resizing? Can anyone help with the automatic resizing?

    Thanks!

  2. #2
    Join Date
    Aug 2010
    Location
    Lancs, United Kingdom
    Beans
    1,247
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Gtk::Image resizing

    See for example http://developer.gnome.org/gtkmm/uns...1_1Pixbuf.html
    Code:
    Glib::RefPtr< Gdk::Pixbuf > 	scale_simple (int dest_width, int dest_height, InterpType interp_type) const
    This function does not modify its object, but returns a new scaled object.

  3. #3
    Join Date
    May 2013
    Beans
    4

    Re: Gtk::Image resizing

    This is a snip of code that i use to re-size my image.
    the simple re-size return the image re-sized without touching the original one.
    Code:
    bool GuiTag::on_draw_original(const ::Cairo::RefPtr< ::Cairo::Context>& cr){
      Glib::RefPtr<Gdk::Pixbuf> image_buf,image_scaled;
    .
    .
    .
       image_scaled = image_buf->scale_simple(new_width,new_height, Gdk::INTERP_BILINEAR);    
       Gdk::Cairo::set_source_pixbuf(cr,image_scaled, (IMAGES_FRAME_WIDTH-new_width)/2, (IMAGES_FRAME_HEIGHT-new_height)/2);
       cr->paint();

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •