這裏是我的代碼:不知道如何做到這一點,而循環
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中讀取。出於某種原因,當我運行註釋循環時,我得到一個ArrayIndexOutOfBoundsException。我該如何解決?提前致謝!
你能粘貼例外嗎? – OscarRyz