[英]Exception java.lang.RuntimeException: setParameters failed
I am getting following error我收到以下错误
Exception java.lang.RuntimeException: setParameters failed
android.hardware.Camera.native_setParameters (Camera.java)
android.hardware.Camera.setParameters (Camera.java:1946)
in code below.在下面的代码中。 I have no clue what wrong i am doing below.
我不知道我在下面做错了什么。
Camera mCamera = Camera.open();
Parameters params = mCamera.getParameters();
if (params.getFlashMode() != null)
params.setFlashMode(Parameters.FLASH_MODE_OFF);
if (nightMode && params.getSceneMode() != null)
params.setSceneMode(Parameters.SCENE_MODE_NIGHT);
if (params.getSupportedFocusModes().contains(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
params.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
} else if (params.getSupportedFocusModes().contains(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
params.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
} else if (params.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_INFINITY)) {
params.setFocusMode(Parameters.FOCUS_MODE_INFINITY);
}
mCamera.setParameters(params);
this error is occurring in some devices like samsung mostly.此错误主要发生在三星等某些设备中。 Requesting for help.Thanks in advance.
请求帮助。提前致谢。
Your params could be not supported by device.设备可能不支持您的参数。 You can detect available focus modes with
getSupportedFocusModes
method of Camera.Parameters
class.您可以使用
Camera.Parameters
类的getSupportedFocusModes
方法检测可用的对焦模式。 If some mode doesn't contain in this list, you can't set it to your camera.如果某些模式不包含在此列表中,则您无法将其设置为您的相机。
Edit编辑
As Alex said in comment you can see error message in logcat.正如亚历克斯在评论中所说,您可以在 logcat 中看到错误消息。
you must check if the focus mode supported by the user device, not all devices has camera focus mode, you do it like this:您必须检查用户设备是否支持对焦模式,并非所有设备都具有相机对焦模式,您可以这样做:
public boolean support_focus(Camera camera){
Camera.Parameters parameters = camera.getParameters();
List<String> focusModes = parameters.getSupportedFocusModes();
if (focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO))
return true;
else
return false;
}
this check if device support FOCUS_MODE_AUTO, change that with your desired Parameter.这个检查设备是否支持 FOCUS_MODE_AUTO,用你想要的参数改变它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.