Unable to display PNG image from file in Gtk::Window

I am having some trouble displaying a PNG file in a Gtk::Window. I tried creating a Gtk::Pixbuf from the file and then create a Gtk::Image using that. Then I tried adding the Gtk::Image to the Gtk::Window but all I'm getting a blank screen. What am I doing wrong?

class CMainWindow : public Gtk::ApplicationWindow

    Glib::RefPtr<Gdk::Pixbuf> pic = Gdk::Pixbuf::create_from_file("image.png");
    Gtk::Image* img = Gtk::manage(new Gtk::Image(pic));

CMainWIndow::~CMainWindow() {}

int main(int argc, char** argv)
    app = Gtk::Application::create(argc, argv,"org.gtkmm.examples.base");
    CMainWindow c;
    return app->run(c);

Read more here: https://stackoverflow.com/questions/64395489/unable-to-display-png-image-from-file-in-gtkwindow

Content Attribution

This content was originally published by anshah at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: