Saving Screen to PNG File

Hi folks,

I have a working program drawing to the screen. I decided to add the ability to save the screen after a set number of iterations to a file. I used as a basis for my code the doc found here:…-il=ofImage

Following is the relevant code from my program:

void testApp::setup(){  
    picout.allocate(ofGetScreenWidth(), ofGetScreenHeight(), OF_IMAGE_COLOR);  
void testApp::update(){  
    if(counter > 500) {  
        picout.grabScreen(0,0,picout.width, picout.height);  

To all appearances the program works fine and it creates the correctly sized output file. The problem is the output file is nothing but a black picture. So why does everything appear to work but produces an apparently empty PNG file?


Have you tried adding the code in the draw method?

Dunno if that’ll change things :slight_smile:

Hi Alejandro,

Yes I did try it there as well although it should not matter where I put the code to copy the current screen to the png file. Haven’t had time to do more experimenting but hope to find some time this evening.

Thanks for your suggestion.

I have identified the problem.

With ofSetBackgroundAuto(true), everything works fine.

With ofSetBackgroundAuto(false), grabScreen and saveImage stop working.