Android的摄像机2 API - 检测时,我们有重点 [英] Android Camera2 API - Detect when we have focus
问题描述
所以,我设法创造我想用老相机,我想它的方式的功能。
So, I managed to create the functionality i wanted with the old camera the way I wanted it.
使用mCamera.autoFocus(autoFocusCallback);我发现,当我有重点和运行所需的code,而在preVIEW模式。
With mCamera.autoFocus(autoFocusCallback); i detect when I have focus and run the required code while in preview-mode.
现在我有一个很难把握如何做同样的摄像机2 API。
我的第一个想法是,我会使用
Now I have a hard time grasping how to do the same in camera2 API. My first idea was that i'd use
private void process(CaptureResult result) {
switch (mState) {
case STATE_PREVIEW: {
// We have nothing to do when the camera preview is working normally.
int afState = result.get(CaptureResult.CONTROL_AF_STATE);
//if (CaptureResult.CONTROL_AF_STATE == afState) {
Log.d("SOME KIND OF FOCUS", "WE HAVE");
//}
break;
}
}
但我无法找到某种状态,告诉我,我们已经得到了关注的焦点。是否有人有任何想法如何这可以用摄像机2 API做什么?
but I fail to find some kind of state that tells me we have gotten focus. Does someone have any idea how this can be done with Camera2 API?
推荐答案
您已经基本上得到了它。状态列表您可以检查和过渡,可以发现<一个href=\"https://developer.android.com/reference/android/hardware/camera2/CaptureResult.html#CONTROL_AF_STATE\"相对=nofollow>这里。
You've basically got it. The list of states you can check for and their transitions can be found here.
这要看是什么 CONTROL_AF_MODE
你使用,但一般你检查 FOCUSED_LOCKED
或者 PASSIVE_FOCUSED
,虽然你可能想为 NOT_FOCUSED_LOCKED
和的情况下, PASSIVE_UNFOCUSED
案例相机的只是不能的重点放在现场。
It depends on what CONTROL_AF_MODE
you are using, but generally you check for FOCUSED_LOCKED
or perhaps PASSIVE_FOCUSED
, though you may want to have cases for NOT_FOCUSED_LOCKED
and PASSIVE_UNFOCUSED
in case the camera just cannot focus on the scene.
这篇关于Android的摄像机2 API - 检测时,我们有重点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!