diff --git a/Gtkmm3/gtk119_imageviewer2/src/MyImage.cc b/Gtkmm3/gtk119_imageviewer2/src/MyImage.cc index 30dd1de..cfcab9e 100644 --- a/Gtkmm3/gtk119_imageviewer2/src/MyImage.cc +++ b/Gtkmm3/gtk119_imageviewer2/src/MyImage.cc @@ -16,12 +16,14 @@ bool MyImage::on_draw(const Cairo::RefPtr &cr){ int width = image->get_width(); int height = image->get_height(); + //Set the default size for drawing area set_size_request(width,height); // Draw the image in the middle of the drawing area, or (if the image is // larger than the drawing area) draw the middle part of the image. Gdk::Cairo::set_source_pixbuf(cr, image, (width - image->get_width())/2, (height - image->get_height())/2); + cr->paint(); return true; @@ -29,6 +31,10 @@ bool MyImage::on_draw(const Cairo::RefPtr &cr){ void MyImage::set_pixbuf(const Glib::RefPtr &pixbuf) { + if(image){ + image.reset(); + } + image = pixbuf; //ReDraw the draw area