2

我开发了一个 android 应用程序来通过 camerax 扫描 QR 码。预览时如何禁用自动对焦?

没试过

public void initCamera(Fragment fragment, OnQRResultListener onQRResultListener) {
    mOnQRResultListener = onQRResultListener;
    PreviewConfig previewBuild = new PreviewConfig.Builder()
            .setTargetResolution(new Size(getWidth(), getHeight()))
            .setTargetAspectRatio(new Rational(1, 1))
            .setLensFacing(CameraX.LensFacing.FRONT)
            .build();
    preview = new Preview(previewBuild);
    preview.setOnPreviewOutputUpdateListener(new Preview.OnPreviewOutputUpdateListener() {
        @Override
        public void onUpdated(Preview.PreviewOutput output) {
            textureView.setSurfaceTexture(output.getSurfaceTexture());
        }
    });
    HandlerThread analyzerThread = new HandlerThread("BarcodeAnalyzer");
    analyzerThread.start();
    ImageAnalysisConfig analysisBuild = new ImageAnalysisConfig.Builder()
            .setTargetResolution(new Size(getWidth(), getHeight()))
            .setTargetAspectRatio(new Rational(1, 1))
            .setLensFacing(CameraX.LensFacing.FRONT)
            .setImageReaderMode(ImageAnalysis.ImageReaderMode.ACQUIRE_LATEST_IMAGE)
            .setCallbackHandler(new Handler(analyzerThread.getLooper()))
            .build();
    ImageAnalysis analysis = new ImageAnalysis(analysisBuild);
    analysis.setAnalyzer(new QRCodeAnalyzer(onAnalyzerResultListener));
    CameraX.bindToLifecycle(fragment, preview, analysis);
}

它会慢慢扫描 qr 结果

4

2 回答 2

0

请参阅此链接:

https://developer.android.com/reference/androidx/camera/core/FocusMeteringAction.Builder#disableAutoCancel()

另请参阅stackoverflow上的这个答案:

https://stackoverflow.com/a/60095886/8401205

这是一个简单的java版本的小代码段:

FocusMeteringAction action = new FocusMeteringAction.Builder(point, FocusMeteringAction.FLAG_AF).disableAutoCancel().build();

于 2021-03-07T13:15:10.130 回答
0

您可以使用cancelFocusAndMetering()

val cameraProviderFuture = ProcessCameraProvider.getInstance(this)
    cameraProviderFuture.addListener(Runnable {
        // Used to bind the lifecycle of cameras to the lifecycle owner
        val cameraProvider: ProcessCameraProvider = cameraProviderFuture.get()
...
        // Bind use cases to camera
        val camera = cameraProvider.bindToLifecycle(this, cameraSelector, preview, imageCapture)

        camera.cameraControl.cancelFocusAndMetering()
}
于 2021-09-30T12:31:07.827 回答