用android Camera2连续拍摄静态照片

时间:2018-01-11 00:53:46

标签: android android-camera android-camera2

Camera2Basic示例,我修改了代码,使程序每2秒连续拍摄一张照片。它运行正常,但一段时间后它进入相同的状态回调条件,不再拍照:

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;
                }
                else
                {
                    Log.e(TAG,"aeState = " + aeState);
                }
                break;
            }

日志保持打印aeState = 2,即CONTROL_AE_STATE_CONVERGED。我的问题是为什么当AE收敛时代码什么都不做?为什么不将状态更改为STATE_WAITING_NON_PRECAPTURE?

我的意思是为什么不这样做?

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_CONVERGED ||
                    aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE ||
                    aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED) {
                mState = STATE_WAITING_NON_PRECAPTURE;
            }
            else
            {
                Log.e(TAG,"aeState = " + aeState);
            }
            break;
        }

ps:如果我想每2秒拍照一次,我应该在哪里调用takePicture()?目前我在CaptureCallback中调用它,但看起来有一些竞争条件,因为CaptureCallback在后台线程中。

感谢。

1 个答案:

答案 0 :(得分:0)

代码应该在此之前将AE_PRECAPTURE_TRIGGER设置为START;然后它等待看到AE_PRECAPTURE的AE_STATE至少有一个结果进入,以便知道触发器已激活且预捕获已开始。然后等待第一个非PRECAPTURE AE_STATE知道预捕获已经完成。