Why does my jpg/png/bmp look darker than my ppm file even though they have the same pixels?

179 Views Asked by At

I encountered a weird problem: I converted a ppm file into png, jpg, and bmp. Visually, png, jpg, and bmp files look darker. I thought it was something wrong with the pixels so I use the following code to print out the pixels of the png file,

public class testMethods {
  public static void main(String[] args) throws IOException {
    File file = new File("res/35blur.png");
    BufferedImage image = ImageIO.read(file);

    for (int i = 0; i < image.getHeight(); i++) {
      for (int j = 0; j < image.getWidth(); j++) {
        int firstPixel = image.getRGB(j, i);
        int red = (firstPixel >> 16) & 0xFF;
        int green = (firstPixel >> 8) & 0xFF;
        int blue = firstPixel & 0xFF;
        System.out.println(red);
        System.out.println(green);
        System.out.println(blue);
      }
    }
  }
}

But the output are the same as the rgb values in the ppm file. Anyone know what could possibly be the reason for this?

enter image description here

0

There are 0 best solutions below