Understanding BufferedImage.getRGB output values

getRGB(int x, int y) return you the value of color pixel at location (x,y).
You are misinterpreting the returned value.
It is in the binary format. like 11…11010101 and that is given to you as int value.
If you want to get RGB (i.e. Red, Green, Blue) components of that value use Color class. e.g.

Color mycolor = new Color(img.getRGB(x, y));

Then you can get Red, Green, or Blue value by using getRed(), getGreen(), getBlue(), getAlpha(). Then an int value will be returned by these methods in familiar format having value 0 < value < 255

int red = mycolor.getRed();

If you don’t want to use Color class then you will need to use bitwise operations to get its value.

Leave a Comment