解码Android应用程序中的QR码?

时间:2011-03-02 17:43:03

标签: java android qr-code zxing

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

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

无论如何以这种方式解码QR图像?

2 个答案:

答案 0 :(得分:3)

您可以使用ZXing代码。

查看DecodeHandler.java

答案 1 :(得分:1)

您可以简单地使用Mobile Vision API从Image中解码QR码。它非常准确,可以在图像上检测多个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);
                }
            }
相关问题