Skip to content

Instantly share code, notes, and snippets.

@catehstn
Created March 17, 2015 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save catehstn/abe17d87496bad0a603c to your computer and use it in GitHub Desktop.
Save catehstn/abe17d87496bad0a603c to your computer and use it in GitHub Desktop.
/**
* Compare two images.
* @param bitmap1
* @param bitmap2
* @return true iff both images have the same dimensions and pixel values.
*/
public static boolean compareImages(Bitmap bitmap1, Bitmap bitmap2) {
if (bitmap1.getWidth() != bitmap2.getWidth() ||
bitmap1.getHeight() != bitmap2.getHeight()) {
return false;
}
for (int y = 0; y < bitmap1.getHeight(); y++) {
for (int x = 0; x < bitmap1.getWidth(); x++) {
if (bitmap1.getPixel(x, y) != bitmap2.getPixel(x, y)) {
return false;
}
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment