Image comparision

Comparing two Images

This code will compare two images with same picture resolutions.  If the resolutions is changed, then both the images are not equal.

Input
compare2Images(new File(“C:/Compare/Image1.JPG”), new File(“C:/Compare/Image2.JPG”));

Solution
public static void compare2Images(File fileA, File fileB) {
try {
FileInputStream imageInFile = new FileInputStream(fileA);
byte imageData[] = new byte[(int) fileA.length()];
imageInFile.read(imageData);
String image1 = new String(Base64.encodeBase64(imageData));
imageInFile.close();

imageInFile = new FileInputStream(fileB);
imageData = new byte[(int) fileB.length()];
imageInFile.read(imageData);
String image2 = new String(Base64.encodeBase64(imageData));
            imageInFile.close();

if(image1.equals(image2)) {
// Images are equal;
} else {
// Images are not equal;
}
}
catch (Exception e) {
e.printStackTrace();
}
}