本文主要是介绍android 慢动作触发区域对焦,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一、普通模式区域对焦
Android Camera2 实现触摸对焦功能(Touch to Focus) - 简书
关键代码
public void startControlAFRequest(MeteringRectangle rect,CameraCaptureSession.CaptureCallback captureCallback) {MeteringRectangle[] rectangle = new MeteringRectangle[]{rect};// 对焦模式必须设置为AUTOmPreviewBuilder.set(CaptureRequest.CONTROL_AF_MODE,CaptureRequest.CONTROL_AF_MODE_AUTO);//AEmPreviewBuilder.set(CaptureRequest.CONTROL_AE_REGIONS,rectangle);//AF 此处AF和AE用的同一个rect, 实际AE矩形面积比AF稍大, 这样测光效果更好mPreviewBuilder.set(CaptureRequest.CONTROL_AF_REGIONS,rectangle);try {// AE/AF区域设置通过setRepeatingRequest不断发请求mSession.setRepeatingRequest(mPreviewBuilder.build(), null, mHandler);} catch (CameraAccessException e) {e.printStackTrace();}//触发对焦mPreviewBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,CaptureRequest.CONTROL_AF_TRIGGER_START);try {//触发对焦通过capture发送请求, 因为用户点击屏幕后只需触发一次对焦mSession.capture(mPreviewBuilder.build(), captureCallback, mHandler);} catch (CameraAccessException e) {e.printStackTrace();}
}
//触发对焦通过capture发送请求, 因为用户点击屏幕后只需触发一次对焦
mSession.capture(mPreviewBuilder.build(), captureCallback, mHandler);
二、慢动作模式区域对焦
慢动作模式使用上述mSession.capture是无法完成对焦的,需要使用mSession.captureBurst来完成。
2.1 创建List<CaptureRequest>
public List<CaptureRequest> createHighSpeedRequestList(CameraDevice cameraDevice, CameraConstrainedHighSpeedCaptureSession session,int templateType, Surface... surfaces) {CaptureRequest.Builder reqBuilder;List<CaptureRequest> list;try {reqBuilder = cameraDevice.createCaptureRequest(templateType);for (CaptureRequest.Key<?> key : mCaptureRequests.keySet()) {setRequest(reqBuilder, key);}addRequestParameter(reqBuilder);for (Surface surface : surfaces) {reqBuilder.addTarget(surface);}list = session.createHighSpeedRequestList(reqBuilder.build());} catch (CameraAccessException err) {err.printStackTrace();return null;}return list;}
2.2 进行一次对焦动作
List<CaptureRequest> requestList = createHighSpeedRequestList(...);
mSession.captureBurst(requestList, captureCallback, mHandler);
项目经验,仅供参考
这篇关于android 慢动作触发区域对焦的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!