Decoding a QR code in an Android application?

岁酱吖の 提交于 2019-12-04 09:49:42

问题


In Android, Using ZXing we can scan a QR code through phone camera and decode it.

But, in my scenario, the QR code image is stored in the phone itself and I need to decode it.

Is there anyway to decode a QR image in this manner?


回答1:


You can use ZXing code for this.

Check out DecodeHandler.java.




回答2:


You can simply use the Mobile Vision API for decoding a QR Code from Image.It is very accurate and can detect more than one Qr code over image.

You have to include the following library inorder to use Mobile Vision API :

compile '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);
                }
            }


来源:https://stackoverflow.com/questions/5171294/decoding-a-qr-code-in-an-android-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!