【发布时间】:2013-02-20 08:03:19
【问题描述】:
我编写了以下代码来将灰度图像的像素读取到一维数组。 运行代码时我怎么会出错
public class LoadImage {
BufferedImage image;
void load()throws Exception {
File input = new File("lena.png");
image = ImageIO.read(input);
}
public Dimension getImageSize() {
return new Dimension(image.getWidth(), image.getHeight());
}
public int[] getImagePixels() {
int [] dummy = null;
int wid, hgt;
// compute size of the array
wid = image.getWidth();
hgt = image.getHeight();
// start getting the pixels
Raster pixelData;
pixelData = image.getData();
return pixelData.getPixels(0, 0, wid, hgt, dummy);
}
}
主类
public static void main(String[] args) throws IOException, Exception {
LoadImage l = new LoadImage();
l.load();
int pixel[];
pixel= l.getImagePixels();
}
【问题讨论】:
-
确切的错误信息是什么?
-
请发布完整的堆栈跟踪...
-
FileNotFoundException?这就是我在计算机上运行此代码时得到的结果:)
-
@JasonSperske 那是因为您的计算机中没有“lena.png”文件。
-
'int 像素[];'看起来不正确
标签: java image image-processing bufferedimage grayscale