Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
43 lines (33 sloc) 1.15 KB
private void setParameters(){
  Camera.Parameters parameters = mCamera.getParameters();

  List<String> supportedFocusModes = parameters.getSupportedFocusModes();

  if (supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
  	parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
  }

  // API 14 之后, 可以配合 camera.autoFocus(AutoFocusCallback) 使用
  if (supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
    parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
  }
  
  mCamera.setParameters(parameters);
}

private void manualFocus(){
  mCamera.autoFocus(mAutoFocusCallback);
}

private Camera mCamera; // = Camera.open(id);

private AutoFocusCallback mAutoFocusCallback = new AutoFocusCallback() {
	@Override
	public void onAutoFocus(boolean success, Camera camera) {
		if (success) {
		  // ...
		} else {
		  // ...
		}
		
		// 恢复到 FOCUS_MODE_CONTINUOUS_PICTURE 模式
		camera.cancelAutoFocus(); 
	}
};

参考: