ofSaveScreen saves black images (macOS)

Hi everybody!
Thanks to your latest help,
I’ve been able to achieve this https://www.youtube.com/watch?v=-VDUo9aMz7U !
Now I’m trying to save the resulting image. :sunglasses:

I’m using ofSaveScreen after a if check in the draw() loop.
Some time it works fine, saving the current frame as png to the disk… but some other times (with other images in input) it just saves as black frame.
Does anybody knows the reason or some workarounds? :question:
I tried also putting glReadBuffer(GL_FRONT) as read in some other topics.

(macOs 10.11.5 on OF 0.9.3)

(I’m writing this for future lurkers! :smiley: )

After a bit of debugging, I tried with different input/output images and found something interesting.

Premise: the dimensions of my OF window is based on the width and height of the input image.
• If the image I’m saving has an even width and height (eg: 600x570), it saves without problems.
• If width or height are not even (eg: 574x545), the saved image MAY come as a black one.
All input images tested are 8-bit sRGB.
Concerning this last fact, I tested with different images and still I cannot find a common pattern…
Some examples:

600x570 --> :ok:

600x753 --> :ok:

574x545 --> :thumbsdown:

859x816 --> :thumbsdown:

574x545 resized in code to be 574x544 --> :thumbsdown:

Latest test: 574x546 --> :thumbsdown:
It seems not to be related to the dimension of the image, actually…

So there must be something else operating behind the scenes…

The code I’m using for saving images is this:

ofImage screen;
screen.allocate(ofGetWidth(), ofGetHeight(), OF_IMAGE_COLOR);
screen.grabScreen(0, 0, ofGetWidth(), ofGetHeight());
string imageName = "TEST_600x570/"+ofToString(ofGetFrameNum())+".png";

Anybody who has even a slight hint of what’s happening is really welcome! :slight_smile:

Latest UPDATE (02-06-2016):
It seems that resizing one of the dimensions of the image to a power of 2 number solved the issue…
Given that inputImage is of type ofImage, code goes like that:

// Init new width and height of image
int newWidth = inputImage.getWidth();
int newHeight = inputImage.getHeight();
// Find the nearest pow of 2 of biggest image dimension (width or height)
// and resize other dimension according to aspect ratio
if(inputImage.getWidth() >= inputImage.getHeight()){
    //newWidth = pow(2, ceil(log(inputImage.getWidth())/log(2)));
    newWidth = ofNextPow2(ofGetWidth());
    newHeight = newWidth / aspectRatio;
else {
    newHeight = ofNextPow2(ofGetHeight());
    newWidth = newHeight * aspectRatio;
// Resize image according to new pow of 2 size
inputImage.resize(newWidth, newHeight);

Under Linux Ubuntu 16.04, OF version 0.9.8, grabScreen works with widths 1144 and 1364 but gives a black screen with widths 1142 and 1366.
My current hypothesis is that the width must be divisible by 4 but I haven’t done extensive testing.