我一直在使用bookClasses類來操作圖像,並且在嘗試刪除圖像中的紅眼時出現NullPointerException錯誤。下面是代碼:NullPointerException(幫助!)
首先removeRedEye
方法,它是Picture.Java類中:
public void removeRedEye(int startX, int startY, int endX, int endY, Color newColor){
Pixel pixel = null;
for (int x = startX; x < endX; x++){
for (int y = startY; y < endY; y++){
if (pixel.colorDistance(Color.RED) < 167){
pixel.setColor(newColor);
}
}
}
}
}
和測試類:
public class TestRemoveRedEye{
public static void main(String[] args){
String fileName = FileChooser.getMediaPath("//jenny-red.jpg");
Picture jennyPicture = new Picture(fileName);
jennyPicture.removeRedEye(109,91,202,107,java.awt.Color.BLACK);
jennyPicture.explore();
}
}
如果任何人都可以說明爲什麼我的程序ISN」工作它將不勝感激。從removeRedEye方法
jennyPicture.removeRedEye(109,91,202,107,java.awt.Color.BLACK);
從測試類