I have this image:
I'd like to extract the RGB values of this image in an int[]
. This is what I've done so far for PNG images:
File f = new File("t.jpg");
BufferedImage img = ImageIO.read(f);
int[] ib = img.getRGB(0, 0, img.getWidth(), img.getHeight(), null, 0, img.getWidth());
Color c = new Color(ib[0]);
System.out.println(c.getRed() + " " + c.getGreen() + " " + c.getBlue());
But here I get this output: 255 128 128
which is not expected since I clearly see (and have verified in several image editors) that the pixel at (0,0) has these values 255 255 255
.
I noticed that the type returned by img.getType()
is equal to TYPE_3BYTE_BGR so I guess it's a decoding issue happening behind the scene but I can't figure out how to workaround it (or get a clearer understanding of what's happening).
Does anyone would have a suggestion on how to decode this type properly?