1

在Android中,使用ZXing我们可以通过手机摄像头扫描二维码并解码。

但是,在我的场景中,二维码图像存储在手机本身中,我需要对其进行解码。

反正有没有以这种方式解码 QR 图像?

4

2 回答 2

3

您可以为此使用 ZXing 代码。

查看DecodeHandler.java

于 2011-03-02T18:02:46.420 回答
1

您可以简单地使用 Mobile Vision API 从图像中解码 QR 码。它非常准确,可以检测到多个图像上的二维码。

您必须包含以下库才能使用 Mobile Vision API:

编译'com.google.android.gms:play-services-vision:9.6.1'

BarcodeDetector detector =
                new BarcodeDetector.Builder(context)
                        .setBarcodeFormats(Barcode.DATA_MATRIX | Barcode.QR_CODE)
                        .build();
        if(!detector.isOperational()){
            Log.d("QR_READ","Could not set up the detector!");
        }
        Frame frame = new Frame.Builder().setBitmap(bitmap).build();
        SparseArray<Barcode> barcodes = detector.detect(frame);
            Log.d("QR_READ","-barcodeLength-"+barcodes.size());
            Barcode thisCode=null;
            if(barcodes.size()==0){
                Log.d("QR_VALUE","--NODATA");
            }
            else if(barcodes.size()==1){
                thisCode = barcodes.valueAt(0);
                Log.d("QR_VALUE","--"+thisCode.rawValue);
            }
            else{
                for(int iter=0;iter<barcodes.size();iter++) {
                    thisCode = barcodes.valueAt(iter);
                    Log.d("QR_VALUE","--"+thisCode.rawValue);
                }
            }
于 2016-11-11T08:20:12.667 回答