Re: Why does Gtk::Image::set() not work with a Cairo::Surface?



I made a simple test by changing some lines in the ActionBar example in the gtkmm tutorial. In file
https://git.gnome.org/browse/gtkmm-documentation/tree/examples/book/actionbar/examplewindow.cc
I replaced
m_face_image.set_from_icon_name("face-cool", Gtk::ICON_SIZE_DIALOG);
by
  Cairo::RefPtr<Cairo::ImageSurface> isurface = Cairo::ImageSurface::create_from_png("rain.png");
  m_face_image.set(isurface);

It works! The umbrella is shown. (rain.png comes from another example in the tutorial.)

Can you please show a complete, but small, program that does not work.

Kjell

Den 2015-07-25 07:59, Adam Nielsen skrev:
Hi all,

I'm trying to display a static image in a Gtk::Image widget.  I have
the image as a Cairo::ImageSurface, so I assumed I could call
Gtk::Image::set(surface) however this does not work - the widget
changes from the "missing image" icon to blank (all white.)

If instead I call Gdk::Pixbuf::create(surface, 0, 0, width, height) and
pass the resulting Pixbuf to Gtk::Image::set() then it works.

I am wondering why the set() call works when I pass a Gdk::Pixbuf, but
not when I pass a Cairo::Surface?

Passing the Cairo::Surface is easier for me (don't have to have code to
retrieve image dimensions) so I'd rather do that if I can.

  auto cimg = Cairo::ImageSurface::create(...);
  ...
  Glib::RefPtr<Gtk::Image> ctImage = ...

  // This works
  //ctImage->set(Gdk::Pixbuf::create(cimg, 0, 0, width, height));

  // This doesn't work - why?
  ctImage->set(cimg);

Many thanks,
Adam.




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