【发布时间】:2013-09-13 16:37:43
【问题描述】:
我在尝试从图像读取像素时收到 ArrayIndexoutOfBoundsException。该代码返回某些图像的像素值,而不是其他图像的像素值。我尝试搜索网络,其中大多数是指从 0 到 n 的读取...
代码如下..任何帮助将不胜感激..
我尝试将图像保存在 bi 中,它被保存了..所以 bi 永远不会得到空值.. 我的图像尺寸始终是 125*150.. 我尝试在 inputFace 中打印值,但在那些不提供像素值的图像中,我什至在打印时都没有得到任何输出...... 分配内存后数组不会初始化为0吗??
提前致谢
private double[] getImageData(String imageFileName) {
BufferedImage bi = null;
double[] inputFace = null;
try{
bi = ImageIO.read(new File(imageFileName));
}catch(IOException ioe){
ioe.printStackTrace();
}
if (bi != null){
int imageWidth = bi.getWidth();
int imageHeight = bi.getHeight();
inputFace = new double[imageWidth * imageHeight];
bi.getData().getPixels(0, 0, imageWidth, imageHeight,inputFace);
}
else
{
System.out.println("Null in bi");
}
return inputFace;
}
【问题讨论】:
-
你试过不预分配 inputFace 吗?正在做
inputFace = bi.getData().getPixels(0, 0, imageWidth, imageHeight,inputFace); -
我也试过了,但它不起作用......
标签: java arrays exception bufferedimage indexoutofboundsexception