Exemplo n.º 1
0
void saveSnapshot(string path) {
    Gtk::DrawingArea* drawArea = 0;
    VRGuiBuilder()->get_widget("glarea", drawArea);
    Glib::RefPtr<Gdk::Drawable> src = drawArea->get_window();
    int smin = min(drawArea->get_width(), drawArea->get_height());
    int u = max(0.0, drawArea->get_width()*0.5 - smin*0.5);
    int v = max(0.0, drawArea->get_height()*0.5 - smin*0.5);
    Glib::RefPtr<Gdk::Pixbuf> pxb = Gdk::Pixbuf::create( src, u, v, smin, smin);
    pxb = pxb->scale_simple(128, 128, Gdk::INTERP_HYPER);
    pxb->save(path, "png");
}
Exemplo n.º 2
0
OSG::ImageRecPtr takeSnapshot() {
    Gtk::DrawingArea* drawArea = 0;
    VRGuiBuilder()->get_widget("glarea", drawArea);
    Glib::RefPtr<Gdk::Drawable> src = drawArea->get_window(); // 24 bits per pixel ( src->get_depth() )
    int w = drawArea->get_width();
    int h = drawArea->get_height();
    w -= w%4; h -= h%4;
    //cout << "PIC FORMAT " << w << " " << h << " " << src->get_depth() << endl;
    Glib::RefPtr<Gdk::Image> img = Glib::wrap( gdk_drawable_get_image(src->gobj(), 0, 0, w, h) );
    Glib::RefPtr<Gdk::Pixbuf> pxb = Glib::wrap( gdk_pixbuf_get_from_image(NULL, img->gobj(), src->get_colormap()->gobj(), 0,0,0,0,w,h) );

    OSG::ImageRecPtr res = OSG::Image::create();
    //Image::set(pixFormat, width, height, depth, mipmapcount, framecount, framedelay, data, type, aloc, sidecount);
    res->set(OSG::Image::OSG_RGB_PF, w, h, 1, 0, 1, 0, (const unsigned char*)pxb->get_pixels(), OSG::Image::OSG_UINT8_IMAGEDATA, true, 1);
    return res;
}