如果你添加
到你的清单,它并不意味着相机会autofocus
.这意味着您允许您的应用程序使用相机硬件或处理自动对焦的软件.
声明的目的是通知任何外部实体您的应用程序所依赖的硬件和软件功能集.
要将相机设置为焦点,可以将此方法添加到您的CameraView
班级:
private void setFocus(String mParameter) { Camera.Parameters mParameters = mCamera.getParameters(); mParameters.setFocusMode(mParameter); mCamera.setParameters(mParameters); }
然后surfaceChanged()
像这样调用此方法:
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { ...//your code here // Set focus mode to continuous picture setFocus(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); // Start camera preview mCamera.startPreview(); }
你可以选择focus parameters
:
String FOCUS_MODE_AUTO自动对焦模式.
String FOCUS_MODE_CONTINUOUS_PICTURE用于拍摄照片的连续自动对焦模式.
String FOCUS_MODE_CONTINUOUS_VIDEO用于视频录制的连续自动对焦模式.
String FOCUS_MODE_EDOF扩展景深(EDOF).
字符串FOCUS_MODE_FIXED焦点是固定的.
String FOCUS_MODE_INFINITY焦点设置为无穷大.
String FOCUS_MODE_MACRO宏(特写)对焦模式.
//set camera to continually auto-focus Camera.Parameters params = c.getParameters(); //*EDIT*//params.setFocusMode("continuous-picture"); //It is better to use defined constraints as opposed to String, thanks to AbdelHady params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); c.setParameters(params);