[英]Android camera is in landscape but used in portrait mode
I hold my phone in "portrait mode" but the cameraPreview
is in mode landscape (ie I see something rotated by 90 degrees). 我将手机放在“人像模式”下,但
cameraPreview
处于横向模式(即,我看到某些物体旋转了90度)。 When I turned the phone to hold it in "landscape mode" the preview is fine and is in "landscape mode", the image is not rotated. 当我转动手机将其置于“横向模式”时,预览效果很好,并且处于“横向模式”,图像未旋转。 I do not have access to
Camera.setDisplayOrientation(int)
, so I can't use the method explained here . 我无权访问
Camera.setDisplayOrientation(int)
,因此无法使用此处说明的方法。
I've tried: 我试过了:
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);
}
Try setting the camera's display orientation by using: 尝试使用以下方法设置相机的显示方向:
Camera camera;
...
camera.setDisplayOrientation(90);
Put it in the surfaceCreated(SurfaceHolder holder) method. 将其放在surfaceCreated(SurfaceHolderholder)方法中。 This worked for me when I had a similar problem.
当我遇到类似的问题时,这对我有用。
ok so I've solve the problem In the "surfaceCreated" method do 好的,所以我已经解决了“ surfaceCreated”方法中的问题
Method rotateMethod;
rotateMethod = android.hardware.Camera.class.getMethod("setDisplayOrientation", int.class);
rotateMethod.invoke(camera, 90);
just after 刚过
camera = Camera.open();
(cf: Camera is wrong unless keyboard is open ) (cf: 除非打开键盘,否则相机错误 )
add code in AndroidManifest.xml Activity in your workspace project. 在工作区项目的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.