例外:“main”java.lang.ArrayIndexOutOfBoundsException:坐标超出界限

时间:2013-07-28 12:51:24

标签: java image bufferedimage indexoutofboundsexception

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Coordinate out of bounds!
    at sun.awt.image.IntegerInterleavedRaster.setDataElements(IntegerInterleavedRaster.java:301)
    at java.awt.image.BufferedImage.setRGB(BufferedImage.java:988)
    at MyManager.imageMan.fazerNova(imageMan.java:354)
    at MyManager.imageMan.main(imageMan.java:472)

我需要一些帮助。

  public static BufferedImage fazerNova(int abc[],BufferedImage img) {

    BufferedImage teste1 = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
    for (int k = 0; k < abc.length; k++) {
        int w1 = abc[k] % img.getWidth();
        int h1 = (int) Math.floor(abc[k] / img.getWidth());
        teste1.setRGB(w1, h1, 0xffffff);
    }
    return teste1;
}

1 个答案:

答案 0 :(得分:0)

看一下BufferedImage Documentation,它写得清楚:

  

如果坐标不是,则可能抛出ArrayOutOfBoundsException   在界限。但是,不保证显式边界检查。

所以你确实超出了图像的尺寸。