ofImage.grabScreen() captures the current frame to a PNG in bin/data
openFrameworks provides a one-shot screen capture via ofImage::grabScreen(x, y, width, height), which copies the framebuffer region into an ofImage object. Calling save(filename) on that object writes a PNG to the project’s bin/data directory. The canonical pattern binds this to a keyPressed() handler so capture is on-demand. grabScreen() reads the GPU framebuffer after draw() has finished — placing it inside draw() itself would create an ordering conflict.
Examples
// ofApp.h: ofImage img; void ofApp::keyPressed(int key){ if(key == ‘x’){ img.grabScreen(0, 0, ofGetWidth(), ofGetHeight()); img.save(“screenshot.png”); } }
Assessment
Why does grabScreen() go inside keyPressed() rather than inside draw()? What folder does the file land in, and why?