我正在为类似于ios11的相机应用程序实现Qr代码扫描程序。 我在相机应用程序中出现对焦环时正在扫描Qr代码。
/**
* Show AF target in center of preview.
*/
private void startPassiveFocus() {
// TODO: make mFocusController final and remove null check.
if (mFocusController == null) {
return;
}
// TODO: Some passive focus scans may trigger on a location
// instead of the center of the screen.
mFocusController.showPassiveFocusAtCenter();
if(decodeFrameTask != null){
if(decodeFrameTask.getStatus() == AsyncTask.Status.RUNNING){
// QR scan currently in progress
stopQRCodeReader();
}
} else {
startQrCodeReader();
}
}
我异步调用解码zxing Reader
public DecodeFrameTask(CaptureModule view, AppController apController, CameraActivity mActivity) {
mCaptureModule = new WeakReference<>(view);
appController = apController;
runAsync = 0;
activity = mActivity;
}
protected Result doInBackground(byte[]... params) {
final CaptureModule view = mCaptureModule.get();
final PlanarYUVLuminanceSource source =
view.mCameraManager.buildLuminanceSource(activity.getScreenPreviewByteData(), appController.getCameraAppUI().getSurfaceWidth(),
appController.getCameraAppUI().getSurfaceHeight());
final HybridBinarizer hybBin = new HybridBinarizer(source);
final BinaryBitmap bitmap = new BinaryBitmap(hybBin);
try {
return view.mQRCodeReader.decode(bitmap);
} catch (ChecksumException e) {
Log.d(TAG, "ChecksumException", e);
} catch (NotFoundException e) {
Log.d(TAG, "No QR Code found");
} catch (FormatException e) {
Log.d(TAG, "FormatException", e);
} finally {
view.mQRCodeReader.reset();
}
}
return null;
}
protected void onPostExecute(Result result) {
super.onPostExecute(result);
runAsync = 1;
if(result != null){
Log.d(TAG, "QR Text ----->", result.getText());
}else if(result == null){
Log.d(TAG, "Errorreading QRcode ");
}
}
public void startQrCodeReader() {
mQRCodeReader = new QRCodeReader();
if(mAppController != null) {
decodeFrameTask = new DecodeFrameTask(this, mAppController, mActivity);
decodeFrameTask.execute();
}
}
public void stopQRCodeReader() {
if (decodeFrameTask != null) {
decodeFrameTask.cancel(true);
decodeFrameTask = null;
}
}
我得到的结果为null。请让我知道我在哪里使用zxing库到相机应用程序出错了