Re: Saving DrawingArea to jpeg file



On 14/09/11 06:55, Smie wrote:
Hi all.
How can I save DrawingAreato a jpeg file?

I wrote this code, but it is working only for visible area. I have been
working on that all day, and I gave up.


     Glib::RefPtr<Gdk::Drawable>  drawable =
static_cast<Glib::RefPtr<Gdk::Drawable>  >(get_window());

     Glib::RefPtr<Gdk::Pixbuf>  pixbuf = Gdk::Pixbuf::create(drawable,
                                        0,
                                        0,
                                        get_width(),
                                        get_height());

     if (pixbuf)
         pixbuf->save("filename.jpeg", "jpeg");



If you've got a DrawingArea in a viewport of some sort (so there is nonviewable area), you might be best to look at Gtk::Layout. In addition, if you're using a viewport, try get_bin_window() instead of get_window().

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