java 在 Android 应用程序中解码二维码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5171294/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Decoding a QR code in an Android application?
提问by Veera
In Android, Using ZXingwe can scan a QR code through phone camera and decode it.
在Android中,使用ZXing我们可以通过手机摄像头扫描二维码并对其进行解码。
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?
无论如何以这种方式解码QR图像?
回答by Matthew Willis
回答by VivekTamilarasan
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.
您可以简单地使用 Mobile Vision API 从图像中解码 QR 码。它非常准确,可以检测图像上的多个 Qr 码。
You have to include the following library inorder to use Mobile Vision API :
您必须包含以下库才能使用 Mobile Vision API:
compile 'com.google.android.gms:play-services-vision:9.6.1'
编译'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);
}
}