boolean compareSuccess = compareImages("src/main/1.jpg","src/test/resources/bag_frame2.gif", "src/test/resources/ex.gif");
//(input1,input2,outputfile)
//(boolean=true if same image...false if changes in image)
compareImages (String data,String data1, String diff) {
CompareCmd compare = new CompareCmd();
// For metric-output
compare.setErrorConsumer(StandardStream.STDERR);
IMOperation cmpOp = new IMOperation();
// Set the compare metric
cmpOp.metric("mae");
// Add the expected image
cmpOp.addImage(data);
// Add the current image
cmpOp.addImage(data1);
// This stores the difference
cmpOp.addImage(diff);
try {
// Do the compare
compare.run(cmpOp);
return true;
}
catch (Exception ex) {
return false;
}
}
试试这个。别忘了导入 im4java 或 maven