Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <gtkmm.h>
- #include <iostream>
- #include <cstring>
- #include <vector>
- class MainWindow
- :
- public Gtk::Window
- {
- public:
- MainWindow();
- virtual ~MainWindow() {}
- private:
- Gtk::Image image;
- Glib::RefPtr<Gdk::Pixbuf> ref_orig, ref_dest;
- };
- MainWindow::MainWindow()
- :
- ref_orig (Gdk::Pixbuf::create_from_file ("./image.png"))
- {
- set_title ("Show Image");
- set_position (Gtk::WIN_POS_CENTER);
- const guint8* raw = ref_orig->get_pixels();
- const std::vector<guint8> image_pixels (raw, raw + ref_orig->get_byte_length());
- ref_dest =
- Gdk::Pixbuf::create_from_data (
- image_pixels.data(), Gdk::COLORSPACE_RGB,
- ref_orig->get_has_alpha(), ref_orig->get_bits_per_sample(),
- ref_orig->get_width(), ref_orig->get_height(), ref_orig->get_rowstride());
- image.set (ref_dest);
- add (image);
- show_all_children();
- }
- int main (int argc, char *argv[])
- {
- Glib::RefPtr<Gtk::Application> app = Gtk::Application::create();
- MainWindow main_window;
- return app->run (main_window);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement