Advertisement
Guest User

Gtkmm Show Image MainFoo

a guest
Feb 24th, 2015
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <gtkmm.h>
  2.  
  3. #include <iostream>
  4. #include <cstring>
  5. #include <vector>
  6.  
  7. int main (int argc, char *argv[])
  8. {
  9.     Glib::RefPtr<Gtk::Application> app = Gtk::Application::create();
  10.  
  11.     Gtk::Window main_window;
  12.  
  13.     main_window.set_title ("Show Image");
  14.     main_window.set_position (Gtk::WIN_POS_CENTER);
  15.  
  16.     Glib::RefPtr<Gdk::Pixbuf> ref_orig = Gdk::Pixbuf::create_from_file ("./image.png");
  17.  
  18.     const guint8* raw = ref_orig->get_pixels();
  19.     const std::vector<guint8> image_pixels (raw, raw + ref_orig->get_byte_length());
  20.  
  21.     Glib::RefPtr<Gdk::Pixbuf> ref_dest =
  22.         Gdk::Pixbuf::create_from_data (
  23.             image_pixels.data(), Gdk::COLORSPACE_RGB,
  24.             ref_orig->get_has_alpha(), ref_orig->get_bits_per_sample(),
  25.             ref_orig->get_width(), ref_orig->get_height(), ref_orig->get_rowstride());
  26.  
  27.     Gtk::Image image;
  28.     image.set (ref_dest);
  29.  
  30.     main_window.add (image);
  31.  
  32.     main_window.show_all_children();
  33.    
  34.     return app->run (main_window);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement