user interface - Gtkmm - Save Gtk::DrawingArea to file -
i have gtk::drawingarea inside gtk::scrolledwindow. i'm trying save drawingarea file, following in drawingarea signal_draw()'s handler :
cairo::refptr<cairo::surface> surf = context -> get_target(); surf -> write_to_png("image");
but saves part of drawing area visible in scrolledwindow. how save full image, including part not visible?
also, can in handler of signal_draw, because there can cairo::context. posible context anywhere else?
edit:
thanks andlabs's link got working:
#include <gtkmm.h> #include <cairomm/context.h> #include <cairomm/enums.h> bool draw(const cairo::refptr<cairo::context>& c){ c->set_source_rgb(0,0,0); c->rectangle(400,50,50,50); c->fill(); return true; } int main(int argc, char* argv[]){ glib::refptr<gtk::application> app = gtk::application::create(argc, argv, "my.test"); glib::refptr<gtk::builder> builder = gtk::builder::create(); builder -> add_from_file("gui.glade"); gtk::drawingarea* drawing; gtk::window* win; builder -> get_widget("window", win); builder -> get_widget("drawing", drawing); drawing->signal_draw().connect(sigc::ptr_fun(&draw)); cairo::refptr<cairo::surface> surface; surface = cairo::imagesurface::create(cairo::format_argb32,500,300); cairo::refptr<cairo::context> c = cairo::context::create(surface); draw(c); surface->write_to_png("image"); app->run(*win); }
now, can set drawingarea's context context created in main(), don't have call draw(c) manually keep them synced?
Comments
Post a Comment