In this example we will show you how to save window content to the graphic file and how to implement this functionality in your Cinder application. This could be useful to save output of a graphics algorithm.
We will add a window content saving function to your application:
Add necessary headers:
#include "cinder/ImageIo.h" #include "cinder/Utilities.h"
Add property to your application's main class:
bool mMakeScreenshot;
Set a default value inside the
setup
method:mMakeScreenshot = false;
Implement the
keyDown
method as follows:void MainApp::keyDown(KeyEvent event) { if(event.getChar() == 's') { mMakeScreenshot = true; } }
Add the following code at the end of the
draw
method:if(mMakeScreenshot) { mMakeScreenshot = false; writeImage( getDocumentsDirectory() / fs::path("MainApp_screenshot.png"), copyWindowSurface() ); }