How to save each frame?

Hi, is there a way in OF to save each frame like in Processing:

// Saves each frame as line-000001.png, line-000002.png, etc.
  saveFrame("line-######.png");

I do this (see below) but it stops the loop and save many times the same image with diferent name :frowning:

void ofApp::keyPressed(int key){

    string filename;
    filename = "screen1" + ofToString(imgnum)+ ".png";
    ofSaveScreen(filename);

    imgnum++;

}

thanks
mariana

Instead of doing graphic operations in keyPressed you should just set a parameter that makes it happen in update

like

bool doSaveScreen = false;
void ofApp::keyPressed(int key){

    doSaveScreen = true;
}

and back up in update()

void ofApp::update()
{
    if(doSaveScreen)
    {
        ofSaveScreen(ofToString(ofGetFrameNum())+".png");
        doSaveScreen = false;
    }
}
3 Likes

thank you!!
It works very nice :smile: