Here is a function to Compare two images in JAVA.
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.PixelGrabber;
import java.io.File;
public static String processImage() {
System.out.println("Executing processImage Keyword");
try {
String file1 = "D:\\Images\\images.JPEG";
String file2 = "D:\\Images\\images2.JPEG";
Image pic1= Toolkit.getDefaultToolkit().getImage(file1);
Image pic2= Toolkit.getDefaultToolkit().getImage(file2);
try {
PixelGrabber grab11 = new PixelGrabber(pic1, 0, 0, -1, -1,
false);
PixelGrabber grab21 = new PixelGrabber(pic2, 0, 0, -1, -1,
false);
int[] array1= null;
if (grab11.grabPixels()) {
int width = grab11.getWidth();
int height = grab11.getHeight();
array1= new int[width * height];
array1= (int[]) grab11.getPixels();
}
int[] array2 = null;
if (grab21.grabPixels()) {
int width = grab21.getWidth();
int height = grab21.getHeight();
array2 = new int[width * height];
array2 = (int[]) grab21.getPixels();
}
System.out.println("Pixels equal: "
+ java.util.Arrays.equals(array1, array2 ));
} catch (InterruptedException e1) {
e1.printStackTrace();
}
return "Pass";
} catch (Throwable t) {
// report error
return "Fail - " + t.getMessage();
}
}
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.PixelGrabber;
import java.io.File;
public static String processImage() {
System.out.println("Executing processImage Keyword");
try {
String file1 = "D:\\Images\\images.JPEG";
String file2 = "D:\\Images\\images2.JPEG";
Image pic1= Toolkit.getDefaultToolkit().getImage(file1);
Image pic2= Toolkit.getDefaultToolkit().getImage(file2);
try {
PixelGrabber grab11 = new PixelGrabber(pic1, 0, 0, -1, -1,
false);
PixelGrabber grab21 = new PixelGrabber(pic2, 0, 0, -1, -1,
false);
int[] array1= null;
if (grab11.grabPixels()) {
int width = grab11.getWidth();
int height = grab11.getHeight();
array1= new int[width * height];
array1= (int[]) grab11.getPixels();
}
int[] array2 = null;
if (grab21.grabPixels()) {
int width = grab21.getWidth();
int height = grab21.getHeight();
array2 = new int[width * height];
array2 = (int[]) grab21.getPixels();
}
System.out.println("Pixels equal: "
+ java.util.Arrays.equals(array1, array2 ));
} catch (InterruptedException e1) {
e1.printStackTrace();
}
return "Pass";
} catch (Throwable t) {
// report error
return "Fail - " + t.getMessage();
}
}
@ruchi goyal please don't post this type of sit article...
ReplyDeleteplease don't waist visitor's times.
ReplyDeleteA cheater, taken all the things from
ReplyDeletehttp://manthapavankumar.wordpress.com/2012/11/25/comparing-two-images-in-java/
Miss Cheater , you should be sued for what you are doing & should be punished.
Adding 1 to variable name instead of grab1 you have changed to grab11. just simple shit. u r doing.
Stop doing this
The information which you have provided is very good. It is very useful who is looking for selenium Online Training Hyderabad
ReplyDelete