ImageListener.java 2.21 KB
package example;

import cn.fw.dalaran.common.utils.ImageUtils;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

public class ImageListener implements ActionListener {
    private Graphics graphics = null;

    int[][] imagePixArr1;
    int[][] imagePixArr2;

    // set
    public void setGraphics(Graphics graphics) {
        this.graphics = graphics;
    }

    public ImageListener() throws Exception {
        File imageFile1 = ImageUtils.convertFileByUrl("https://gate.feewee.cn/file/show?fid=0684ce9b0d384ff1a1070c61b7ed376c");
        File imageFile2 = ImageUtils.convertFileByUrl("https://gate.feewee.cn/file/show?fid=0aff5b6acf6040459b6d5e69f1290c3b");
        //File imageFile2 = ImageUtils.convertFileByUrl("https://p2.a.yximgs.com/upic/2022/01/20/20/BMjAyMjAxMjAyMDEyMTZfNDcwOTM0NDgyXzY1MzMwMDA5Mjk0XzJfMw==_B0296c8ed5afa94b9b7a06dd1612c3ecb.jpg?tag=1-1642748356-nil-0-ndrgo4aid6-21e0d82706b2e935&clientCacheKey=3x4xb3uvxtpibvc.jpg&di=abd4f314&bp=10000");
        /*File imageFile1 = new File("C:\\Users\\wmy3969\\Desktop\\2.png");
        File imageFile2 = new File("C:\\Users\\wmy3969\\Desktop\\2022.4.23-4.30短视频背景封面jpg\\春风十里焕新鲸喜\\1.png");*/
        imagePixArr1 = ImageUtils.readImagePixel(new File(ImageUtils.modifyResolution(imageFile1.getPath(), "C:\\Users\\wmy3969\\Desktop", 512, 512)));
        imagePixArr2 = ImageUtils.readImagePixel(new File(ImageUtils.modifyResolution(imageFile2.getPath(), "C:\\Users\\wmy3969\\Desktop", 512, 512)));
        /*imagePixArr1 = ImageUtils.readImagePixel(imageFile1);
        imagePixArr2 = ImageUtils.readImagePixel(imageFile2);*/
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        // 先获取按钮上的字符串 用来判断调用什么代码
        String buttonStr = e.getActionCommand();
        if (buttonStr.equals("加载图片")) {
            ImageUtils.drawImage(graphics, imagePixArr1, 30, 100, null);
            ImageUtils.drawImage(graphics, imagePixArr2, 774, 100, null);
        } else if (buttonStr.equals("开始匹配")) {
            ImageUtils.calcSimilarity(ImageUtils.getFingerprint(imagePixArr1), ImageUtils.getFingerprint(imagePixArr2));
        }
    }
}