我是android的新手。我正在使用Google vision-api依赖于Qr代码扫描,请点击以下链接:
https://www.youtube.com/watch?v=INVNULTm56o。
但它扫描整个屏幕。如果我想从限制区域或边界读取Qr代码而不最小化屏幕是否可能?让我知道谢谢。
我在我的应用程序中设计了这个边界,我只想从边界读取Qr代码: -
答案 0 :(得分:0)
您可以将Zxing Library用于 QR码扫描 r以及条码扫描器。
如果您想自定义布局:
您还可以使用此库处理onCreate()
,onResume()
,onPause()
。
build.gradle(模块:应用)文件
compile 'me.dm7.barcodescanner:zxing:1.9'
Java代码 ScanActivity :
public class ScanActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler{
private ZXingScannerView mScannerView;
@Override
public void onCreate(Bundle state) {
super.onCreate(state);
mScannerView = new ZXingScannerView(this); // Programmatically initialize the scanner view
setContentView(mScannerView); // Set the scanner view as the content view
}
@Override
public void onResume() {
super.onResume();
mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
mScannerView.startCamera(); // Start camera on resume
}
@Override
public void onPause() {
super.onPause();
mScannerView.stopCamera(); // Stop camera on pause
}
@Override
public void handleResult(Result rawResult) {
// Do something with the result here
Log.v("tag", rawResult.getText()); // Prints scan results
Log.v("tag", rawResult.getBarcodeFormat().toString()); // Prints the scan format (qrcode, pdf417 etc.)
// If you would like to resume scanning, call this method below:
//mScannerView.resumeCameraPreview(this);
}
}
您将获得扫描仪结果:
@Override
public void handleResult(Result rawResult) {
// Do something with the result here
Log.v("tag", rawResult.getText()); // Prints scan results
Log.v("tag", rawResult.getBarcodeFormat().toString()); // Prints the scan format (qrcode, pdf417 etc.)
// If you would like to resume scanning, call this method below:
//mScannerView.resumeCameraPreview(this);
}