Problem You need to make a snapshot of a widget.
Solution This code is based on advice given by Jeroen in a post to the FOX users' mailing list:
void makeSnapshot(const FXDrawable* drawable) { // Construct and create an FXImage object FXPNGImage snapshot(getApp(), NULL, 0, drawable->getWidth(), drawable->getHeight()); snapshot.create();
// Create a window device context and lock it onto the image FXDCWindow dc(&snapshot);
// Draw from the widget to this dc.drawArea(drawable, 0, 0, drawable->getWidth(), drawable->getHeight(), 0, 0);
// Release lock dc.end();
// Grab pixels from server side back to client side snapshot.restore();
// Save recovered pixels to a file FXFileStream stream; if (stream.open("snapshot.png", FXStreamSave)) { snapshot.savePixels(stream); stream.close(); } }
Contributor(s) Lyle Johnson
|