#include #include class Test : public Gtk::Window { public: Test (); private: // Override virtual function virtual bool on_button_press_event(GdkEventButton* event); Gtk::OffscreenWindow m_pw; Gtk::Image* m_pi; }; Test::Test () { set_size_request ( 160, 90 ); set_position ( Gtk::WIN_POS_CENTER ); try { // Put something offscreen Gtk::Label* pl = new Gtk::Label ( "Test OffscreenWindow" ); m_pw.add ( *pl ); m_pw.show_all (); // Retrieve it Glib::RefPtr refPixbuf = m_pw.get_pixbuf (); // Show pixbuf dimensions set_title ( Glib::ustring::format ( refPixbuf->get_width (), " x ", refPixbuf->get_height () ) ); // Show pixbuf contents onscreen m_pi = new Gtk::Image ( refPixbuf ); add ( *m_pi ); //refPixbuf->save ( "pixbuf.png", "png" ); //system ( "eog pixbuf.png" ); show_all_children (); } catch ( const Glib::FileError& ex ) { std::cerr << "File error: " << ex.what () << std::endl; } catch ( const Gdk::PixbufError& ex ) { std::cerr << "Pixbuf error: " << ex.what () << std::endl; } } bool Test::on_button_press_event(GdkEventButton*) { Glib::RefPtr refPixbuf = m_pw.get_pixbuf(); m_pi->set(refPixbuf); return false; } int main ( int argc, char *argv[] ) { Glib::RefPtr refApp = Gtk::Application::create ( argc, argv, "org.gtkmm.example" ); Test window; return refApp->run ( window ); }