我正在开发一个相机叠加应用,其中使用了相机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)
请帮我。可能的原因是什么?