相机parameters.setFocusMode不工作(camera parameters.set

2019-06-26 12:22发布

我试图将相机设置为自动对焦ON ......但每当我设置setFocusMode应用程序崩溃..

java.lang.RuntimeException: setParameters failed

我的代码是:

Camera.Parameters parameters = camera.getParameters();
parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
Camera.Size size = getBestPreviewSize(width, height, parameters);
Camera.Size pictureSize = getSmallestPictureSize(parameters);

if (size != null && pictureSize != null) {
    parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
    parameters.setPreviewSize(size.width, size.height);
    parameters.setPictureSize(pictureSize.width, pictureSize.height);
    parameters.setPictureFormat(ImageFormat.JPEG);
    camera.setParameters(parameters);
    cameraConfigured = true;
}

为什么会有这样的错误来了?

Answer 1:

您需要验证,如果相机支持你想要的对焦模式。

做这样的:

Camera.Parameters parameters = camera.getParameters();
List<String> focusModes = parameters.getSupportedFocusModes();
if (focusModes.contains(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO))
    parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
camera.setParameters(parameters);


文章来源: camera parameters.setFocusMode is not working