繁体   English   中英

如何创建像素值数组?

[英]How to create an array of pixel values?

我正在尝试创建一个具有Java中图像的所有RGB值的双脚本数组。 之后,我要查看像素是黑色还是白色。 但是,下面的代码给我一个ArrayIndexOutofBounds错误,我不确定为什么。 任何帮助将不胜感激!

int[][] imageArr = new int[image.getTileHeight()+1][image.getTileWidth()+1];
    for (int a=0; a<image.getTileHeight(); a++)
    {
        for (int b=0; b<image.getTileWidth(); b++)
        {
            imageArr[a][b] = image.getRGB(a,b);               
        }
    }

错误的堆栈跟踪:

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 image2.main(image2.java:34)

如果要获取完整的图像,则需要在循环和数组初始化中使用getHeightgetWidth而不是getTileHeightgetTileWidth

这些导致getRBG在尝试获取嵌入BufferedImage中的Raster数据的图像时抛出ArrayIndexOutOfBounds

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM