小编faz*_*man的帖子

线程“main”中的异常 java.lang.ArrayIndexOutOfBoundsException:坐标越界

BufferedImage image = ImageIO.read(new File(img path));  

int width = image.getWidth();
int height = image.getHeight();
int[][] result = new int[height][width];

for (int row = 0; row < height; row++) {
  for (int col = 0; col < width; col++) {
     result[row][col] = image.getRGB(row, col);
  }
}
Run Code Online (Sandbox Code Playgroud)

这是我得到的例外:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!
at sun.awt.image.ByteInterleavedRaster.getDataElements(ByteInterleavedRaster.java:301)
at java.awt.image.BufferedImage.getRGB(BufferedImage.java:871)
at PlantExtraction.main(PlantExtraction.java:46)
Run Code Online (Sandbox Code Playgroud)

我怎样才能消除这些异常?

java bufferedimage javax.imageio

3
推荐指数
1
解决办法
6630
查看次数

标签 统计

bufferedimage ×1

java ×1

javax.imageio ×1