Here's a PoC program, that creates a blank image, sets RGB values, stores it as PNG and reads back the exact same values:
public static void main(String[] args) throws IOException {
BufferedImage image = new BufferedImage(256, 4, BufferedImage.TYPE_INT_ARGB);
for (int x = 0; x < image.getWidth(); x++) {
image.setRGB(x, 0, 0x00ffffff | x << 24); // alter alpha
image.setRGB(x, 1, 0xff000000 | x << 16); // alter red
image.setRGB(x, 2, 0xff000000 | x << 8); // alter green
image.setRGB(x, 3, 0xff000000 | x ); // alter blue
}
File file = File.createTempFile("temp-", ".png");
if (!ImageIO.write(image, "PNG", file)) {
System.err.println("Could not write image");
System.exit(1);
}
BufferedImage read = ImageIO.read(file);
if (read.getWidth() != image.getWidth() || read.getHeight() != image.getHeight()) {
System.err.println("Dimensions differ!");
System.exit(1);
}
for (int y = 0; y < read.getHeight(); y++) {
for (int x = 0; x < read.getWidth(); x++) {
// Uncomment this line, if you want to verify the values
// System.out.printf("image.getRGB(%3d, %d): #%08x\n", x, y, image.getRGB(x, y));
if (image.getRGB(x, y) != read.getRGB(x, y)) {
System.err.printf("pixel differ @ [%3d,%d]: #%08x\n", x, y, read.getRGB(x, y));
}
}
}
}
I get no difference between the original image, and the one that I wrote and read back (using Java 1.8.0_131 on Windows).