I'm rather new to java, and I am trying to make a program to do various things to a picture given by the user (rotate, flip, invert, etc). However, I have run into an error in this piece of code when trying to invert the image's colours:
public static int[][] invert(int[][] result){
int[][]inver = new int[255][255];
for(int y = result.length-1; y>=0; y--){
for(int x = result.length-1; x>=0; x--){
inver[y][x]=result[y][x];
}
}
return inver;
}
The 2d array 'result' in the parameters is an array with numbers relating to the colours of the image's pixels, a length of 255 by 255 and integers between 0-255 filling it. The error I get is an ArrayOutOfBounds exception of 328 at the line 'inver[y][x]=result[y][x];'. From my understanding, this exception is caused when you try to access an array element that isn't there, but I don't know why it would be that big of a number or what is causing it. Any suggestions on how to fix this would be greatly apreciated