首页 > 解决方案 > QR 码未在图像中检测到 BarcodeDetector

问题描述

我已经使用 BarcodeDetector 从图像中实现 QR 码检测

 BarcodeDetector detector = new BarcodeDetector.Builder(getApplicationContext())
                    .setBarcodeFormats(/*Barcode.DATA_MATRIX | Barcode.QR_CODE|*/Barcode.QR_CODE)
                    .build();
    if (detector.isOperational()) {
        Log.e("QR_READ", "Could not set up the detector!");


    Frame frame = new Frame.Builder().setBitmap(pageBitmap).build();

    QRCodeList = detector.detect(frame);
}

这里 QRCodeList 是空的,但该图像中有 QR 码。但是有些图像正在使用代码,但有些图像没有检测到,但是我在网上检查的那些图像,那些正在使用的图像。为什么那个代码没有检测到二维码?

标签: androidqr-code

解决方案


也许这只是您正在扫描的那些二维码的问题。尝试使用在线 QRCode 生成器并检查它是否适用于您将生成的每个 QRCode。

此外,您可以打印扫描返回的原始值。这是 Kotlin 但您可以将其转换为 Java 。像这样的东西:

val rawScanValue: String = QRCodeList.valueAt(0).rawValue
// or toast or whatever
Log.d('RAWVALUE',rawScanValue)

推荐阅读