我在一周前发布了一款名为“Cam Shooter”的应用程序,它使用了相机表面视图和一个消防按钮。我收到了20多条关于此错误的报告:
java.lang.RuntimeException: set display orientation failed
at android.hardware.Camera.setDisplayOrientation(Native Method)
at com.jouni.camsniper.MainActivity.surfaceChanged(MainActivity.java:139)
at android.view.SurfaceView.updateWindow(SurfaceView.java:573)
at android.view.SurfaceView.setFrame(SurfaceView.java:296)
at android.view.View.layout(View.java:7199)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
at android.view.View.layout(View.java:7205)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:912)
at android.view.View.layout(View.java:7205)
at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
at android.view.View.layout(View.java:7205)
at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
at android.view.View.layout(View.java:7205)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1145)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1870)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
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:875)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633)
at dalvik.system.NativeStart.main(Native Method)
在我的代码中有一些线来修复相机的旋转和纵横比,可能是造成问题。
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
Parameters parameters = mCamera.getParameters();
List<Camera.Size> previewSizes = parameters.getSupportedPreviewSizes();
Camera.Size previewSize = previewSizes.get(4); //480h x 720w
parameters.setPreviewSize(previewSize.width, previewSize.height);
parameters.setFlashMode(Parameters.FLASH_MODE_AUTO);
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
mCamera.setParameters(parameters);
Display display = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
if(display.getRotation() == Surface.ROTATION_0) {
mCamera.setDisplayOrientation(90); // LINE 139
} else if(display.getRotation() == Surface.ROTATION_270) {
mCamera.setDisplayOrientation(180);
}
mCamera.startPreview();
}
有谁知道如何摆脱这个错误?
答案 0 :(得分:0)
您是否找到了解决问题的方法?我想知道你是否在设置预览显示的新旋转之前是否试图停止捕捉和绘制预览帧?例如:
mCamera.stopPreview();
mCamera.setDisplayOrientation(degrees);
mCamera.startPreview();