java.lang.RuntimeException:相机Api中的setParameters失败

时间:2013-02-06 13:34:52

标签: android camera

我正在开发Camera overly应用程序,因为我使用相机api进行预览和叠加效果。我在某些手机中出现强制关闭错误,并且不会发生其他手机。

我的代码:

parameters = camera.getParameters(); 
List<Size> sizes = parameters.getSupportedPreviewSizes(); 
Size optimalSize = getOptimalPreviewSize(sizes, w, h); 
parameters.setPreviewSize(optimalSize.width, optimalSize.height);
parameters.setColorEffect(Camera.Parameters.EFFECT_SOLARIZE);
setCameraDisplayOrientation(MainActivity.this,0, camera); 
camera.getParameters(); 
camera.setParameters(parameters);

这些是我得到的调用堆栈

    java.lang.RuntimeException: setParameters failed
    at android.hardware.Camera.native_setParameters(Native Method)
    at android.hardware.Camera.setParameters(Camera.java:1046)
    at com.androidpixels.watercamera.MainActivity.surfaceChanged(MainActivity.java:1241)
    at android.view.SurfaceView.updateWindow(SurfaceView.java:575)
    at android.view.SurfaceView.updateWindow(SurfaceView.java:407)
    at android.view.SurfaceView.dispatchDraw(SurfaceView.java:352)
    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
    at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
    at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
    at android.view.View.draw(View.java:6936)
    at android.widget.FrameLayout.draw(FrameLayout.java:357)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1917)
    at android.view.ViewRoot.draw(ViewRoot.java:1530)
    at android.view.ViewRoot.performTraversals(ViewRoot.java:1266)
    at android.view.ViewRoot.handleMessage(ViewRoot.java:1868)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:130)
    at android.app.ActivityThread.main(ActivityThread.java:3693)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
    at dalvik.system.NativeStart.main(Native Method)

请帮帮我。可能是什么原因?

1 个答案:

答案 0 :(得分:7)

Android相机参数因设备而异。您需要在设置之前验证设备是否支持您尝试设置的参数,请参阅此Camera SetParameters Doc

您可以通过以下方式查询支持的参数

  • 获取参数对象:Camera.Parameters params = mCamera.getParameters();
  • 然后查询该对象的特定参数,比如PreviewSize:

    params.getSupportedPreviewSizes()