From d3113b2a1c4c7a6c44cb0eeaf728c302cb899792 Mon Sep 17 00:00:00 2001
From: whycxzp <glperry@163.com>
Date: 星期四, 07 十一月 2024 14:43:16 +0800
Subject: [PATCH] 解压

---
 src/main/java/com/whyc/util/ImageDiff.java |   67 +++++++++++++++++++++++++++++++++
 1 files changed, 67 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/whyc/util/ImageDiff.java b/src/main/java/com/whyc/util/ImageDiff.java
index 319d157..70c536d 100644
--- a/src/main/java/com/whyc/util/ImageDiff.java
+++ b/src/main/java/com/whyc/util/ImageDiff.java
@@ -1,11 +1,15 @@
 package com.whyc.util;
 
 import javax.imageio.ImageIO;
+import javax.xml.bind.DatatypeConverter;
 import java.awt.*;
 import java.awt.image.BufferedImage;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
 
 public class ImageDiff {
 
@@ -167,8 +171,71 @@
     }
 
 }
+    public static boolean compareImagesCheck(String srcImgPath, String targetImgPath) {
+        String hash1 = calculateMD5(srcImgPath);
+        String hash2 = calculateMD5(targetImgPath);
+        // 姣旇緝涓や釜鍝堝笇鍊兼槸鍚︾浉鍚�
+        return hash1 != null && hash2 != null && hash1.equals(hash2);
+        /*boolean sameImage = true;
+        try {
 
 
+
+            BufferedImage srcImg = ImageIO.read(new File(srcImgPath));
+            BufferedImage targetImg = ImageIO.read(new File(targetImgPath));
+
+            int srcHeight = srcImg.getHeight();
+            int srcWidth = srcImg.getWidth();
+
+            //淇敼寰呮瘮杈冨浘鐗囩殑灏哄浠ラ�傚簲婧愬浘鐗囩殑灏哄
+            targetImg = changeImageSize(targetImg, srcHeight, srcWidth);
+
+
+            int srcRgb;
+            int targetRgb;
+            for (int h = 0; h < srcHeight; h++) {
+                for (int w = 0; w < srcWidth; w++) {
+                    srcRgb = srcImg.getRGB(w, h);
+                    targetRgb = targetImg.getRGB(w, h);
+                    *//*if (Math.abs(getRed(srcRgb) - getRed(targetRgb)) > DIFF_ALLOW_RANGE ||
+                            Math.abs(getGreen(srcRgb) - getGreen(targetRgb)) > DIFF_ALLOW_RANGE ||
+                            Math.abs(getBlue(srcRgb) - getBlue(targetRgb)) > DIFF_ALLOW_RANGE) {
+                        diffImg.setRGB(w, h, RGB_RED);
+                        diffPointCount++;
+                    }
+                }*//*
+                    if (Math.abs(targetRgb - srcRgb) > DIFF_ALLOW_RANGE) { //鍍忕礌鐐逛笉鍚�,鍒ゆ柇涓轰笉鍚屽浘鐗�
+                        return false;
+                    }
+                }
+            }
+
+
+        }catch (Exception ex){
+            ex.printStackTrace();
+        }
+        return sameImage;*/
+    }
+    public static String calculateMD5(String filePath) {
+        try (FileInputStream fis = new FileInputStream(filePath)) {
+            // 鑾峰彇MD5鎽樿绠楁硶鐨� MessageDigest 瀹炰緥
+            MessageDigest md = MessageDigest.getInstance("MD5");
+
+            // 璇诲彇鏂囦欢鍐呭骞舵洿鏂版憳瑕�
+            byte[] buffer = new byte[1024];
+            int bytesRead;
+            while ((bytesRead = fis.read(buffer)) != -1) {
+                md.update(buffer, 0, bytesRead);
+            }
+
+            // 璁$畻鍝堝笇鍊煎苟杞崲涓哄崄鍏繘鍒跺瓧绗︿覆
+            byte[] digest = md.digest();
+            return DatatypeConverter.printHexBinary(digest).toUpperCase();
+        } catch (NoSuchAlgorithmException | IOException e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
     public static void main(String[] args) throws IOException {
 
         compareImages("C:\\\\Users\\\\29550\\\\Desktop\\\\褰撳墠椤圭洰\\\\202207鍥剧焊绠$悊\\\\鍥剧焊鍗囩骇\\\\fbo-60010nt-t-j-002_a11-dwg.png",

--
Gitblit v1.9.1