I am trying to create a double-scripted array that has all the RGB values of an image in java. Afterwards, I want to see whether the pixel is black or white. However, the following code gives me an ArrayIndexOutofBounds Error and I'm not sure why. Any help would be greatly appreciated!
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);
}
}
Stack Trace of error:
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)