捕获图像camera2时预览已锁定

时间:2017-10-12 05:20:38

标签: java android camera android-camera2

我已经使用camera2 Api实现了突发图像捕获,它的工作正常需要6 fps ..但是我的问题是当它拍照时它会聚焦锁定这就是为什么预览被锁定一小段时间,我想删除它预览锁定,我希望预览始终启用,这里是我的静态捕捉爆发,我正在关注googles camera2示例

private void captuteStillImage() {
    try {
        count = 0;
        CaptureRequest.Builder captureBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);

        int rotation = getWindowManager().getDefaultDisplay().getRotation();
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));

        CameraCaptureSession.CaptureCallback captureCallback = new CameraCaptureSession.CaptureCallback() {
            @Override
            public void onCaptureCompleted(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
                super.onCaptureCompleted(session, request, result);
                //unlockFocus();
                count++;
                Log.e("count",count+"");
                runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    tv_count.setText(count+"");

                }
            });

                if (count >= MAX_CAPTURE) {
                   unlockFocus();
                }
                Log.e("Image Capture", "Successfully");
            }
        };

        // mCameraCaptureSession.capture(captureBuilder.build(), captureCallback, null);

        List<CaptureRequest> captureList = new ArrayList<CaptureRequest>();
        captureBuilder.addTarget(mImageReader.getSurface());
        for (int i = 0; i < MAX_CAPTURE; i++) {
            captureList.add(captureBuilder.build());
        }
        //mCameraCaptureSession.stopRepeating();
        mCameraCaptureSession.captureBurst(captureList, captureCallback, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

1 个答案:

答案 0 :(得分:1)

我在camera2basic(https://github.com/googlesamples/android-Camera2Basic)上进行了一些实验,发现如果我在获取图像之后和保存之前调用了解锁,我可以更快地恢复预览 - 我还删除了对unLockFocus的原始调用在captureCallback中。

>sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.5 LTS

locale:
 [1] LC_CTYPE=fr_FR.UTF-8       LC_NUMERIC=C               LC_TIME=fr_FR.UTF-8        LC_COLLATE=fr_FR.UTF-8    
 [5] LC_MONETARY=fr_FR.UTF-8    LC_MESSAGES=fr_FR.UTF-8    LC_PAPER=fr_FR.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=fr_FR.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] Cairo_1.5-9


>capabilities("cairo")
    cairo 
    FALSE 

然而,Camera2Basic有很多回调,我发现当你开始测试活动或片段被暂停和恢复的场景时,特别是如果你的应用还有其他异步回调,那么很容易进入竞争条件可能会导致意外行为或崩溃。

如果您只是想要一张能够在拍照时更快地返回预览的相机的简单示例,那么基本的FotoApparat示例也值得一看: