Question: Write a method isSame that takes two pictures and checks to see if the two pictures are exactly the same ( returns true or false.

Write a method isSame that takes two pictures and checks to see if the two pictures are exactly the same (returns true or false.)
This is part of the APCSA Steganography Lab, activity 3. I have written a method that compares the RGB values of each Pixel object in each picture's 2D array, but it does not work, and always returns true.
I am unsure why it fails. Code is below
Pixel[][] pArr = p.getPixels2D();
Pixel[][] p2Arr = p2.getPixels2D();
if(pArr.length != p2Arr.length || pArr[0].length != p2Arr[0].length){
return false;
}
for(int k =0; k < pArr.length; k++){
for(int j =0; j < pArr[0].length; j++){
int r1= pArr[k][j].getRed();
int r2= p2Arr[k][j].getRed();
int g1= pArr[k][j].getGreen();
int g2= p2Arr[k][j].getGreen();
int b1= pArr[k][j].getBlue();
int b2= p2Arr[k][j].getBlue();
if(r1!= r2|| g1!= g2|| b1!= b2){
return false;
}
}
}
return true;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!