[英]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)
如果要獲取完整的圖像,則需要在循環和數組初始化中使用getHeight
和getWidth
而不是getTileHeight
和getTileWidth
。
這些導致getRBG
在嘗試獲取嵌入BufferedImage
中的Raster
數據的圖像時拋出ArrayIndexOutOfBounds
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.