12

我正在尝试创建一个应用程序,该应用程序使用camera2 API从服务中获取一些照片。

我可以让应用程序从基于Camera2Basic 示例的片段中很好地拍照。

但是,当我尝试移至服务时,图像无法正确完成捕获。它永远不会超过自动曝光预捕获状态。

我把它缩小到没有预览的问题。我通过采用Camera2Basic代码并删除预览来组合一个测试片段,这会导致相同的问题。

我根据 Camera2Basic 示例整理了一个有问题的测试片段,我基本上只是删除了预览代码。此处上传的片段代码http://pastebin.ca/3182401

我得到了onCaptureCompleted()回调,但是当我在这里检查相机自动曝光状态时,它仍处于CONTROL_AE_STATE_PRECAPTURE状态。

如果其中一个相机状态仍处于预捕获状态,那么捕获将完成对我来说没有任何意义。

有人知道这里可能会发生什么吗?

4

2 回答 2

1

文档中没有提到它,但是 onCaptureCompleted 实际上是在发送请求时调用的,而不是在预捕获或自动对焦序列完成时调用。Camera2Basic 依赖于不断运行的预览,因为预览充当相机状态的恒定监视器。没有它,您将不知道预捕获序列何时真正完成。

于 2015-11-25T23:44:18.720 回答
0

我认为您的逻辑存在缺陷,您将 mState 设置为预捕获状态

private void process(CaptureResult result) {
        switch (mState) {
            case STATE_PREVIEW: {
                // We have nothing to do when the camera preview is working normally.
                break;
            }
            case STATE_WAITING_LOCK: {
                Integer afState = result.get(CaptureResult.CONTROL_AF_STATE);
                if (afState == null) {
                    captureStillPicture();
                } else if (CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED == afState ||
                        CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED == afState) {
                    // CONTROL_AE_STATE can be null on some devices
                    Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
                    if (aeState == null ||
                            aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED) {
                        mState = STATE_PICTURE_TAKEN;
                        captureStillPicture();
                    } else {
                        runPrecaptureSequence();
                    }
                }
                break;
            }
            case STATE_WAITING_PRECAPTURE: {
                // CONTROL_AE_STATE can be null on some devices
                Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
                if (aeState == null ||
                        aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE ||
                        aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED) {
                    mState = STATE_WAITING_NON_PRECAPTURE;
                }
                break;
            }
            case STATE_WAITING_NON_PRECAPTURE: {
                // CONTROL_AE_STATE can be null on some devices
                Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
                if (aeState == null || aeState != CaptureResult.CONTROL_AE_STATE_PRECAPTURE) {
                    mState = STATE_PICTURE_TAKEN;
                    captureStillPicture();
                }
                break;
            }
        }
    }

甚至会输入 case STATE_WAITING_PRECAPTURE 吗?

于 2015-10-20T22:02:45.003 回答