setImageType behaving strangely with ofFbo

Hello. I am trying to have a ofFbo object with an ofImage drawn inside. This image is a copy of another image which has been resized.

    image.loadImage(filePath);
    buffer.allocate(2000, 2000);
    ofImage tempImage;
    image.setImageType(OF_IMAGE_GRAYSCALE);
    tempImage.allocate(image.getWidth(), image.getHeight(), OF_IMAGE_GRAYSCALE);
    tempImage = image;
    image.resize(width, height);
    tempImage.resize(2000, 2000);
    buffer.begin();
    ofClear(ofColor::white);
    ofSetColor(ofColor::white);
    tempImage.draw(0,0);
    buffer.end();

However, when I draw the buffer in the draw() method, I get it tinted in red, and I don’t know where the problem is. If I comment out the setImageType method, the problem disappears. Am I doing something wrong with the allocation or do you know where the problem might be? Thanks!

I believe this is because the underlying texture object uses the red channel to store single-channel (grayscale) image data by default. You should be able to render the image as grayscale by setting

tempImage.getTexture().setRGToRGBASwizzles(true);

Also, you can use ofImageLoadSettings to load your image as grayscale and prevent a redundant reallocation of ofImage caused by setImageType(OF_IMAGE_GRAYSCALE).

ofImageLoadSettings settings;
settings.grayscale = true;
image.loadImage(filePath, settings);