how can i convert image to 2d array?
807597Sep 24 2005 — edited Oct 9 2006hi there,
i need some help to convert image to 2d array.
if the image has 24 bits, i need to convert it to grayscale 8-bits.
this is what i have done, but the values of the 2D array has more than 8bits...
first, i draw image onto graphics of bufferedimage:
BufImage = new BufferedImage(i.getWidth(null), i.getHeight(null), BufferedImage.TYPE_BYTE_GRAY);
Graphics2D g = BufImage.createGraphics();
g.drawImage(i, 0, 0, null);
sceond, use the follwings to convert bufferedImage into 2D array :
int[] rgbs = int[w*h];
bi.getRGB(0, 0, w, h, rgbs, 0, w) ;
for (int j = 0; j<h; j++)
for (int i = 0; i<h; i++){
array[j] = rgbs[j*w+i]; }
can anyone enlighten me on my mistake?