Image can be defined as an abstraction of BufferedImage, it just holds header-like information. Before reading the image pixels, compare the images with their sizes.
File f1;
File f2;
Image i1 = ImageIO.read(f1);
Image i2 = ImageIO.read(f2);
if(i1.getHeight() == i2.getHeight
&& i1.getWidth() == i2.getWİdth) {
BufferedImage b1 = ImageIO.read(f1);
BufferedImage b2 = ImageIO.read(f2);
//compare pixels
}
Image is read way more faster than BufferedImage, as it doesn't get pixels from the file.
For comparison, I suggest a two or more layered pixels comparison. Using random will boost your speed, as finding a non-matching pixel is enough for you.
for(i=0; i<N; i++) {
x = r.nextInt(184);
y = r.nextInt(184);
if(b1.getRGB(x,y) != b2.getRGB(x,y)) {
break;
}
}
If the images pass the randomized comparison, do a pixel by pixel comparison, with breaking the loop in case of finding non-matching pixels. I answered assuming that you need a fast running comparison. For that, I don't suggest MD5 hashing, unless you want to find all duplicate images in a big image directory. If you just want to compare two images, and fast, MD5 don't make much sense, as it's needed to read image's all pixels to checkout a hash value and this decreases speed for one comparison.