Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare two images in Java

Status
Not open for further replies.

saadabc

Programmer
Aug 5, 2004
107
0
0
US
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 think you would do it like this :

Code:
BufferedImage bi ...

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
 


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
 
BufferedImage bi = ImageIO.read(new File("bla.jpg"));

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 

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.


 
I think it is in the ColorModel for the Raster - just read the API documentation for the classes used - you should find your information there.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top