Fwd: Re: OffscreenWindow returns empty pixbuf
- From: Ian Martin <martin_id vodafone co nz>
- To: gtkmm-list <gtkmm-list gnome org>
- Subject: Fwd: Re: OffscreenWindow returns empty pixbuf
- Date: Wed, 03 Sep 2014 09:32:32 +1200
Hi,
2 reasons. The first is you didn't add any image data to it, at least
in the code here.
Second, because (as per the gtkmm docs) "OffscreenWindow is strictly
intended to be used for obtaining snapshots of widgets that are not part
of a normal widget hierarchy."
so writing to the pixbuf returned by it is likely to fail. More usual
would be to create a Gtk::Image and add that to the window, either
writing to the image's pixbuf or if appropriate - and easier- passing an
image file in the constructor.
Ian.
On 02/09/14 11:23, Phil Wolff wrote:
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 );
}
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
https://mail.gnome.org/mailman/listinfo/gtkmm-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]