To improve speed on some backends this may not preserve the font, color, path, or line settings, since these are usually changed afterwards anyway. GSave may also clear the clip, though it will be restored by the destructor.
if (!image.drawn()) { GSave gsave; image->make_current(); draw_graphics_for_image(); // destructor of the GSave happens here } // we can now draw our image into the window: image.draw(x,y,w,h);
Warning: I ran into a C++ misfeature. If you write "GSave gsave()" it will compile into nothing, with no warning (on both GCC and VisualStudio) and your graphics state will end up destroyed.