GitHub - romankh3/image-comparison: Published on Maven Central Java Library that compares 2 images with the same sizes and shows the differences visually by drawing rectangles. Some parts of the image can be excluded from the comparison. Can be used for automation QA tests.Published on Maven Central Java Library that compares 2 images with the same sizes and shows the differences visually by drawing rectangles. Some parts of the image can be excluded from the comparison. Can be used for automation QA tests. - GitHub - romankh3/image-comparison: Published on Maven Central Java Library that compares 2 images with the same sizes and shows the differences visually by drawing rectangles. Some parts of the image can be excluded from the comparison. Can be used for automation QA tests.
https://github.com/romankh3/image-comparison
1、引用jar包
<dependency>
<groupId>com.github.romankh3</groupId>
<artifactId>image-comparison</artifactId>
<version>4.4.0</version>
</dependency>
2、参考代码
/**
* 图片比较演示 https://github.com/romankh3/image-comparison
* 【Github官方图片,略有小改动】
*
* @author chendd
* @date 2023/7/8 14:37
*/
public class GithubImageComparisonTest {
public static void main(String[] args) {
//加载图片
BufferedImage expectedImage = ImageComparisonUtil.readImageFromResources("Expected.png");
BufferedImage actualImage = ImageComparisonUtil.readImageFromResources("Actual.png");
//对比两个图片
ImageComparisonResult imageComparisonResult = new ImageComparison(expectedImage, actualImage).compareImages();
String folder = ImageComparisonUtil.class.getClassLoader().getResource("").getPath();
//存储图片和输出结果
ImageComparisonUtil.saveImage(new File(folder , "Github图片对比结果.png") , imageComparisonResult.getResult());
System.out.println("Github图片对比状态:" + imageComparisonResult.getImageComparisonState());