I am trying to access the pixels of image using method getRGB(). The image I use for this purose is 8-bit image i.e each pixel is represented by 8-bits, hence the possible values are 0-255.
the image I used was png 8-bit image hence the type ‘type_byte_indexed’
if (type == BufferedImage.TYPE_BYTE_INDEXED) {
System.out.println("type.byte.indexed");
System.out.print(h+" "+w);
sourceImage.getRGB(0, 0, w, h, rgbs, 0, w); //rgbs is integer array
for (i = 0; i <10; i++) {
System.out.print(" "+rgbs[i]);
}
System.out.println("rgbs len: " + rgbs.length);
}
The output of the for loop is something ilke:
-12048344 -12174804 -12048344 -12174804 -12174804 .......
I obtain the r,g,b components from it and store in array :
Color c=new Color(rgbs[i]);
r=c.getRed();
g=c.getGreen();
b=c.getBlue();
Now how do I combine again these values so that I can use the setRGB method? Like for 24 bit image we can use
int rgb=65536*pixel[i]+256*pixel[i+1]+pixel[i+2];
The documentation clearly states that the returned values are in ARGB-form:
You can access the underlying buffer (that contains indexed pixels) with