我正在尝试打印每个像素的值,但它在p = 300
. 之前p = 300
,打印所有像素。
orignal.getHeight() = 344;
和orignal.getWidth() = 300;
。
BufferedImage binarized = new BufferedImage(original.getWidth(), original.getHeight(), original.getType());
int p, q;
System.out.println(original.getHeight() + "," + original.getWidth());
for(p=0;p<original.getHeight();p++)
{
for(q = 0; q < original.getWidth(); q++)
{
//System.out.println("goint to get pixel"+"("+p+","+q+")");
int Pixel = binarized.getRGB(p, q);
}
}
错误信息:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!
at sun.awt.image.ByteInterleavedRaster.getDataElements(ByteInterleavedRaster.java:318)
at java.awt.image.BufferedImage.getRGB(BufferedImage.java:888)
at Binarization.binarize(Binarization.java:137)
at Binarization.main(Binarization.java:20)
这是某种内存分配问题吗?