This is strange.
I have code that writes a png image to the disk using ScreenshotAppState.
When I read the png image into a BufferedImage, I am getting a different color for the background.
Here is a test class:
package jme3;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import com.jme3.app.SimpleApplication;
import com.jme3.app.state.ScreenshotAppState;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.Mesh;
import com.jme3.scene.shape.Box;
import com.jme3.system.AppSettings;
import com.jme3.system.JmeContext;
public class ColorTest extends SimpleApplication {
public static final int IMAGE_SIZE = 1024;
public static final ColorRGBA BACKGROUND_COLOR = new ColorRGBA(0.95f,0.95f,0.95f,1);
private ScreenshotAppState ssAppState = null;
@Override
public void simpleInitApp() {
viewPort.setBackgroundColor(BACKGROUND_COLOR);
ssAppState = new ScreenshotAppState("C:"+File.separator+"Tmp"+File.separator+"test");
ssAppState.setIsNumbered(false);
stateManager.attach(ssAppState);
}
@Override
public void simpleUpdate(float tpf) {
Mesh m = new Box(1, 1, 1);
Geometry geom = new Geometry("Fill", m);
Material mat = new Material(assetManager,"Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Green);
geom.setMaterial(mat);
rootNode.attachChild(geom);
ssAppState.takeScreenshot();
stop(true);
}
public static void main(String[] args)
throws Exception {
ColorTest app = new ColorTest();
AppSettings appSettings = new AppSettings(true);
appSettings.setMinHeight(IMAGE_SIZE);
appSettings.setHeight(IMAGE_SIZE);
appSettings.setMinWidth(IMAGE_SIZE);
appSettings.setWidth(IMAGE_SIZE);
app.setSettings(appSettings);
app.start(JmeContext.Type.OffscreenSurface);
System.out.println("Background color is: 0x"+Integer.toHexString(BACKGROUND_COLOR.asIntARGB()));
BufferedImage bufferedImage = ImageIO.read(new File("C:"+File.separator+"Tmp"+File.separator+"testColorTest.png"));
System.out.println("Pixel is 0x"+Integer.toHexString(bufferedImage.getRGB(0,0)));
}
}
The output of my program tells me:
Background color is: 0xfff2f2f2
Pixel is 0xfff9f9f9
I am not expecting that, they should be the same, right?