Compare two images in Java
Compare two images in Java
(OP)
Hi,
I'm trying to compare 2 images to see if they are the exact same or not ....
I'm assuming I would have to compare the bytes representation of the 2 images. I cannot find any methods in the Image, BufferedImage etc classes to get the bytes of the image.
Can anyone help?
Thanks-in-advance.
I'm trying to compare 2 images to see if they are the exact same or not ....
I'm assuming I would have to compare the bytes representation of the 2 images. I cannot find any methods in the Image, BufferedImage etc classes to get the bytes of the image.
Can anyone help?
Thanks-in-advance.

RE: Compare two images in Java
CODE
Raster r = bi.getData();
DataBuffer db = r.getDataBuffer();
int size = db.getSize();
for (int i = 0; i < size; i++) {
int px = db.getElem(i);
}
The first thing to do would be to check that the size of the data buffer are the same for both images, and then if they are, compare both images in the for loop.
--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
http://www.primrose.org.uk
RE: Compare two images in Java
How do I initialize BufferedImage from a pre-existing image saved on the computer hardrive. e.g, C:\test.jpg .
There doesn't seem to be a filename or path parameter in any of the constructors, or other methods.
Thanks.
Waseem
RE: Compare two images in Java
--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
http://www.primrose.org.uk
RE: Compare two images in Java
Thanks - this works!!!
One more question. Do you know where in the data buffer for the image is the information for the background color of the image stored.
RE: Compare two images in Java
--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
http://www.primrose.org.uk