我使用zxing扫描QR码并使用Barcodeview类显示相机预览。截至目前,如果QRCode位于相机预览的正中间,扫描仪的效果很好。但是,如果QR码被放置在预览区域中,而不是中间区域则不会扫描:
以下是相关代码:
获取BarcodeView:
cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
// Create our Preview view and set it as the content of our activity.
mBarcodeView = new BarcodeView(cordova.getActivity());
//Configure the decoder
ArrayList<BarcodeFormat> formatList = new ArrayList<BarcodeFormat>();
formatList.add(BarcodeFormat.QR_CODE);
mBarcodeView.setDecoderFactory(new DefaultDecoderFactory(formatList, null, null));
//Configure the camera (front/back)
CameraSettings settings = new CameraSettings();
settings.setRequestedCameraId(getCurrentCameraId());
mBarcodeView.setCameraSettings(settings);
FrameLayout.LayoutParams cameraPreviewParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
((ViewGroup) webView.getView().getParent()).addView(mBarcodeView, cameraPreviewParams);
cameraPreviewing = true;
webView.getView().bringToFront();
mBarcodeView.resume();
}
});
扫描:
this.nextScanCallback = callbackContext;
final BarcodeCallback b = this;
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
if (mBarcodeView != null) {
mBarcodeView.decodeSingle(b);
}
}
});
如果上述代码不充分,可以找到整个项目here
我试图制作它,以便可以在相机预览的任何部分检测到qr代码,而不仅仅是中间。关于如何实现这一目标的任何想法?