Get java.awt.image.Raster from BufferedImage by calling the getData() method.
Then use
int getSample(int x, int y, int b)
on the resulting object, where b is a color channel (where each color is represented by 8 bits).
For grayscale
b = 0.
For RGB image
b = 0 ==>> R channel, b = 1 ==>> G channel, b = 2 ==>> B channel.
source share