I'm not very good at programming but right now, I need to do program a little Java application and I'm running into a weird problem. I've been trying to solve this for hours now.
Here's the problem: I'm saving a small amount of my screen (20x20) to my program. I do this by looping through every pixel, saving it's RGB into an array via Java.awt.robot. With the following function, the program should save the copied image to 3 arrays (R, G and B) before getting the new area of the screen (I want to compare them later and look for changes). The one damn thing: The old arrays in which I save the data before overwriting the main arrays are always overwriting without me telling them to.
private void fillArrayData(){
oldDataR = dataR; <----- The problem is here. These arrays are now overwritten with the
oldDataG = dataG; <----- current data, just before I write stuff to dataR, G and B.
oldDataB = dataB; <----- As you see, I don't modify oldDataR, G, B later on.
scanArea.x = MouseInfo.getPointerInfo().getLocation().x;
scanArea.y = MouseInfo.getPointerInfo().getLocation().y;
for(int i = 0; i<scanSize; i++){
for(int n = 0; n<scanSize; n++){
dataR[i][n] = (rbt.getPixelColor(scanArea.x+i, scanArea.y+n)).getRed();
dataG[i][n] = (rbt.getPixelColor(scanArea.x+i, scanArea.y+n)).getGreen();
dataB[i][n] = (rbt.getPixelColor(scanArea.x+i, scanArea.y+n)).getBlue();
}
}
}
Even though I never access oldDataR, oldDataG and oldDataB later on, it everytime is equal to the dataR, dataG and dataB after this void finishes. That doesn't make sense as I'm writing new data to the three main arrays (dataR, dataG, dataB) AFTER I saved them to the oldData-Arrays. And yes, I made sure that the data which is received by rbt.getPixelColor is not the same as before.
Please help me, I'm really frustrated by now but need to keep going.