- Mastering openFrameworks:Creative Coding Demystified
- Denis Perevalov
- 276字
- 2021-08-06 16:54:18
Screen grabbing
Sometimes it is desirable to save the picture drawn by your project in the file. You can do it using tools of your operating system, but it's more comfortable to do it right in your project. So let's see how to save the contents of your project screen to an image file.
For such purposes, we need to use the ofImage
class for working with images. Though the class is considered in Chapter 4, Images and Textures, for screen grabbing, it is just enough to understand that the ofImage
object holds an image.
The following code saves the current screen to file on the pressing of the Space bar. It should be added to the testApp::keyPressed()
function as follows:
//Grab the screen image to file if ( key == ' ' ) { ofImage image; //Declare image object //Grab contents of the screen image.grabScreen( 0, 0, ofGetWidth(), ofGetHeight() ); image.saveImage( "screen.png" ); //Save image to file }
The parameters of the image.grabScreen()
function specify the rectangle of the grabbing. In our case, it is the whole screen of the project.
This code is implemented in the 02-2D/06-Spirals
example. Run it and press the Space bar; the contents of the screen will be saved to the bin/data/screen.png
file in your project's folder.
Tip
The PNG files are small and have high quality, so we often use these for screen grabbing. But, writing to a PNG file takes some time because the image has to be compressed. It takes up to several seconds, depending on the CPU and image size. So if you need to save images fast, use the BMP file format.
image.saveImage( "screen.bmp" );
- JavaScript前端開(kāi)發(fā)模塊化教程
- Web應(yīng)用系統(tǒng)開(kāi)發(fā)實(shí)踐(C#)
- Node.js Design Patterns
- JavaScript+DHTML語(yǔ)法與范例詳解詞典
- Debian 7:System Administration Best Practices
- Python語(yǔ)言程序設(shè)計(jì)
- Learning Linux Binary Analysis
- Python高效開(kāi)發(fā)實(shí)戰(zhàn):Django、Tornado、Flask、Twisted(第2版)
- Mastering Unity 2D Game Development(Second Edition)
- Mobile Device Exploitation Cookbook
- R Data Science Essentials
- Python開(kāi)發(fā)基礎(chǔ)
- Android移動(dòng)應(yīng)用開(kāi)發(fā)項(xiàng)目教程
- Getting Started with Electronic Projects
- 原型設(shè)計(jì):打造成功產(chǎn)品的實(shí)用方法及實(shí)踐