[英]Android camera is in landscape but used in portrait mode
我将手机放在“人像模式”下,但cameraPreview
处于横向模式(即,我看到某些物体旋转了90度)。 当我转动手机将其置于“横向模式”时,预览效果很好,并且处于“横向模式”,图像未旋转。 我无权访问Camera.setDisplayOrientation(int)
,因此无法使用此处说明的方法。
我试过了:
Camera.Parameters p = camera.getParameters();
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT)
{
p.set("orientation", "portrait");
p.set("rotation",90);
}
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
{
p.set("orientation", "landscape");
p.set("rotation", 90);
}
尝试使用以下方法设置相机的显示方向:
Camera camera;
...
camera.setDisplayOrientation(90);
将其放在surfaceCreated(SurfaceHolderholder)方法中。 当我遇到类似的问题时,这对我有用。
好的,所以我已经解决了“ surfaceCreated”方法中的问题
Method rotateMethod;
rotateMethod = android.hardware.Camera.class.getMethod("setDisplayOrientation", int.class);
rotateMethod.invoke(camera, 90);
刚过
camera = Camera.open();
(cf: 除非打开键盘,否则相机错误 )
在工作区项目的AndroidManifest.xml活动中添加代码。
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.