Problem with grabScreen (black screenshots)

Hi everyone,

I have a problem with the grabScreen function. It seems that the function works correctly to copy a part of the screen, but most of the time, it returns only a black screenshot. I use the function ofSetBackgroundAuto(false), but it doesn’t works. I don’t know what happens.

Any ideas about what can cause this bug? I will read all your suggestions :slightly_smiling:

Thanks a lot and have a nice day!

Any idea?

Can you run the graphics/imageSaverExample without any issues? If so, could you share the minimum code to reproduce the issue of your sketch?

Hi hubris,

Thanks for your reply.

Yes, I can run the imageSaverExample program.

The only code I can share is this :

void exportImage(const StructImage infos)
string filename = + ‘.’ + infos.ext;
ofImage image;
image.grabScreen(infos.stX, infos.stY, infos.width, infos.height);;

Thanks for your help!

How are you calling exportImage and what are the values for infos?

Hi hubris,

The call of exportImage :


The infos struct :

struct infos
bool partial = false;
int stX = 0;
int stY = 0;
int width = 0; //Changing in the code with position of the mouse
int height = 0; //Changing in the code with position of the mouse
string name = " ";
string ext = “jpg”;
ImageType type = NORMAL_TYPE;

Sorry, I meant when, not how. If you are calling before drawing anything, you will only get the background. Like I said before, it you be easier if you share the minimum code to reproduce the issue. That means how you are doing the setup, update and draw.

Also, and although you are not using it, is NORMAL_TYPE an enum you made? If not, is not an ofImageType enum.

Any chance you are changing window size in ofApp?

Ive run into a bug in some cases where doing this will cause grabScreen to return all black.

mike chambers