I need to write a method using an ArrayList
but I can't quite figure out how to do it.
I was able to do it with just using an array and I was wondering if there was an easy way to change it so that it does implement an ArrayList
.
Here is my current code:
//public ArrayList<Integer> getPixelsInWindow(int wSize, int x, int y) {
//ArrayList<Integer> values = new ArrayList<Integer>();
public int[] getPixelsInWindow(int wSize, int x, int y) {
int [] values;
int xMin = 0;
int xMax = 0;
int yMin = 0;
int yMax = 0;
xMin = x - (wSize / 2);
if (xMin < 0)
xMin = 0;
yMin = y - (wSize / 2);
if (yMin < 0)
yMin = 0;
xMax = x + (wSize / 2);
if (xMax >= rowN)
xMax = rowN - 1;
yMax = y + (wSize / 2);
if (yMax >= columnN)
yMax = columnN - 1;
int differenceX = xMax-xMin;
int differenceY = yMax-yMin;
values = new int[(differenceX + 1) * (differenceY + 1)];
int j = 0;
for(int i = xMin;i < xMax + 1;i++){
for(int k = yMin;k < yMax + 1;k++){
values[j] = img[i][k];
if(j == 0){
}
j++;
}
}
return values;
}
ArrayList
?