Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

camera parameters.setFocusMode is not working

I am trying to set the camera autofocus ON ... but whenever i set setFocusMode the application crashes..

java.lang.RuntimeException: setParameters failed

my code is :

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;
}

Why is this error coming up?

like image 394
Kruti Mevada Avatar asked Jul 24 '12 02:07

Kruti Mevada


1 Answers

You need to verify if the camera supports the FOCUS MODE you wanna.

Do like that:

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);
like image 179
Derzu Avatar answered Oct 02 '22 13:10

Derzu