本讲是android camera专题系列的第44讲,我们介绍android camera2 api专题的af自动对焦实战。
更多资源:
资源 | 描述 |
---|---|
在线课程 | |
知识星球 | 星球名称:深入浅出android camera 星球id: 17296815 |
极客笔记圈 |
连续(被动)对焦(continuous af)
判断支持哪些af mode
int [] supported_focus_modes = characteristics.get(cameracharacteristics.control_af_available_modes); // android format
camera_features.supported_focus_values = convertfocusmodestovalues(supported_focus_modes, camera_features.minimum_focus_distance); // convert to our format (also resorts)
设置af mode
private void setfocusmode(capturerequest.builder builder) {
if( has_af_mode ) {
if( mydebug.log )
log.i(tag, "[af_practise] setfocusmode change af mode to " af_mode);
builder.set(capturerequest.control_af_mode, af_mode);
}
else {
if( mydebug.log ) {
log.i(tag, "af mode left at " builder.get(capturerequest.control_af_mode));
}
}
}
监听af results
if (mydebug.log) {
if (result.get(captureresult.control_af_state) != null) {
int afstate = result.get(captureresult.control_af_state);
string afstatestr = "";
switch (afstate) {
case captureresult.control_af_state_inactive:
afstatestr = "inactive";
break;
case captureresult.control_af_state_passive_scan:
afstatestr = "passive_scan";
break;
case captureresult.control_af_state_passive_focused:
afstatestr = "passive_focused";
break;
case captureresult.control_af_state_active_scan:
afstatestr = "active_scan";
break;
case captureresult.control_af_state_focused_locked:
afstatestr = "focused_locked";
break;
case captureresult.control_af_state_not_focused_locked:
afstatestr = "not_focused_locked";
break;
case captureresult.control_af_state_passive_unfocused:
afstatestr = "passive_unfocused";
break;
default:
break;
}
if (mprintresultcounter % 30 == 0 ||
result.get(captureresult.lens_state) == captureresult.lens_state_moving) {
log.i(tag, "[af_practise] af_state:" afstatestr
", af mode:" result.get(captureresult.control_af_mode)
", af scene changed:" result.get(captureresult.control_af_scene_change)
", lens state:" result.get(captureresult.lens_state)
", focus distance:" result.get(captureresult.lens_focus_distance)
", focus range:" result.get(captureresult.lens_focus_range));
}
}
}
主动对焦(touch af)
geekcamera2 代码逻辑:
preview#touchevent
|---->cameracontroller2#setfocusandmeteringarea
|-------->camerasettings#setafregions //设置对焦区域
|---->cameracontroller2#autofocus // 触发对焦
cameracontroller2#handlestatechange //监听touch af结果