Вот мой код:
public static void decodeThis(BufferedImage im, String outputFile)
throws FileNotFoundException{
int w = im.getWidth();
int h=im.getHeight();
int[] arr=im.getRGB(0, 0, w, h, null, 0, w);
int[] eightBit=new int[8];
int counter=0;
String[] aString=new String[arr.length];
PrintStream out=new PrintStream(new File(outputFile));
double value=0;
int intVal=0;
while (counter<arr.length){
for (int j=0;j<eightBit.length;j++){
eightBit[j] = arr[j+counter] & 1; //Extracts least significant bit, puts into eightBit array.
}
value=0;
for (int x=0;x<eightBit.length;x++){
value+=eightBit[x]*(Math.pow(2,x));
}
intVal=(int)value;
out.print((char)intVal);
counter=counter+8;
}
}
Что я хочу сделать, это прочитать, извлечь и преобразовать в символ 8 бит из arr, пока еще есть пиксели, оставшиеся дочитать в обр.По какой-то причине, когда я запускаю закомментированный цикл for, я получаю ArrayIndexOutOfBoundsException.Как это исправить?Заранее спасибо!