java同时识别多个二维码

java同时识别多个二维码

package com.example.qrcoderecov.test;

import com.google.zxing.*;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.multi.qrcode.QRCodeMultiReader;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class QRCodeDetector {

    public static List<String> readQRCodes(BufferedImage image) throws NotFoundException {
        List<String> qrCodeData = new ArrayList<>();
        LuminanceSource source = new BufferedImageLuminanceSource(image);
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
        QRCodeMultiReader reader = new QRCodeMultiReader();
        for (Result result : reader.decodeMultiple(bitmap, null)) {
            qrCodeData.add(result.getText());
        }
        return qrCodeData;
    }

    public static void main(String[] args) {
        try {
            BufferedImage image = ImageIO.read(new File("D://20231009-170908.jpg"));
            List<String> qrCodeData = readQRCodes(image);
            System.out.println("二维码数据: " + qrCodeData);
        } catch (IOException | NotFoundException e) {
            System.out.println("读取二维码失败: " + e.getMessage());
        }
    }
}

另外:https://github.com/micjahn/ZXing.Net/issues/104


<dependency>
    <groupId>com.google.zxinggroupId>
    <artifactId>coreartifactId>
    <version>3.4.1version>
dependency>
<dependency>
    <groupId>com.google.zxinggroupId>
    <artifactId>javaseartifactId>
    <version>3.4.1version>
dependency>

你可能感兴趣的:(java,python,开发语言)