我正在开发相机过度应用程序,因为我正在使用相机 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)
请帮我。可能是什么原因?