需要幫助。我正在做一個將圖片合併爲一個的程序。我正在使用Windows的樣本圖片進行測試,並且工作正常。我的問題是,我有一個導致NullPointerException的圖像。這是我的代碼。ImageIO.read結果null
int imageHeight = 0;
List<Integer> widthList = new ArrayList<Integer>();
List<Integer> chunkHeight = new ArrayList<Integer>();
File[] imgFiles = new File[chunks];
for (int x = 0; x < chunks; x++) {
imgFiles[x] = new File(tempDirectory + newFileName + (x + 1) + ".png");
}
BufferedImage[] buffImages = new BufferedImage[chunks];
for (int i = 0; i < chunks; i++) {
buffImages[i] = ImageIO.read(imgFiles[i]);
chunkHeight.add(buffImages[i].getHeight());
imageHeight = imageHeight + buffImages[i].getHeight();
widthList.add(buffImages[i].getWidth());
}
我在BufferedImage的getHeight()中遇到了NullPointer問題。我唯一的發現是當我在Photoshop中打開圖像時,出現錯誤「無法完成請求,因爲文件格式模塊無法解析文件」。謝謝。
編輯: 這裏是我的鏈接圖像我用:http://www.mediafire.com/download/5bx322a08c29uae/image2.png
圖像不能被photsohop解析。你確定它是一個圖像文件嗎? – ItachiUchiha
是的,我想。我可以打開並查看圖像,也可以在Paint中進行編輯。 – eclee01
圖像出現問題,將其替換爲一組新圖像並重試 – ItachiUchiha