OffscreenWindow returns empty pixbuf



Can anybody tell me why this code returns a properly sized Pixbuf with no image data?

#include <gtkmm.h>
#include <iostream>

class Test : public Gtk::Window
{
public:
    Test ();
};

Test::Test ()
{
    set_size_request ( 160, 90 );
    set_position ( Gtk::WIN_POS_CENTER );
    try {
        // Put something offscreen
        Gtk::OffscreenWindow* pw = new Gtk::OffscreenWindow ();
        Gtk::Label* pl = new Gtk::Label ( "Test OffscreenWindow" );
        pw->add ( *pl );
        pw->show_all ();
        // Retrieve it
        Glib::RefPtr<Gdk::Pixbuf > refPixbuf = pw->get_pixbuf ();
        // Show pixbuf dimensions
set_title ( Glib::ustring::format ( refPixbuf->get_width (), " x ",
                refPixbuf->get_height () ) );
        // Show pixbuf contents onscreen
        Gtk::Image* pi = new Gtk::Image ( refPixbuf );
        add ( *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;
    }
}

int main ( int argc, char *argv[] )
{
Glib::RefPtr<Gtk::Application> refApp = Gtk::Application::create ( argc,
            argv, "org.gtkmm.example" );
    Test window;
    return refApp->run ( window );
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]