[英]Use camera in landscape when my app is in portrait
I've tried every way to accomplish my desired behaviour but nothing seems to work. 我已经尝试过各种方式来实现我想要的行为,但似乎没有任何工作。
My app is locked in portrait mode (I don't want a landscape UI) but I want to be able to switch the camera display to show a camera preview in portrait and landscape mode alternatively. 我的应用程序被锁定在纵向模式(我不想要横向UI)但我希望能够切换相机显示以交替显示纵向和横向模式的相机预览 。
I'm not interested in capturing images. 我对拍摄图像不感兴趣。
To show the preview in portrait I simply do: 要以纵向显示预览,我只需:
camera.setDisplayOrientation(90);
and my preview works fine, but, when I try to show the camera preview in landscape mode, I do: 我的预览工作正常,但是,当我尝试在横向模式下显示相机预览时,我会:
camera.setDisplayOrientation(0);
and the preview actually rotates, but the image from camera is not rotated, and the final result is just a portrait image rotated to landscape. 并且预览实际上是旋转的,但是来自相机的图像没有旋转,最终结果只是旋转到横向的肖像图像。
I've tried every way: 我尝试过各种方式:
1) rotate the camera with parameters.setRotation()
but this affects only the final image saved and has nothing to do with the preview; 1)使用
parameters.setRotation()
)旋转相机,但这只影响保存的最终图像,与预览无关;
2) set parameters.set("orientation", "landscape")
but this seems to have no effect (maybe an old and not yet supported command?); 2)设置
parameters.set("orientation", "landscape")
但这似乎没有效果(可能是一个旧的,尚未支持的命令?);
3) set every combination of the methods below, but nothing, the only way to effectively rotate the image originate from camera seems to be physically rotate my device… 3)设置下面方法的每个组合,但没有,有效旋转图像的唯一方法来自相机似乎是物理旋转我的设备...
This is a practical demonstration of what I mean: 这是我的意思的实际演示:
As you can see, parameters.setRotation()
do not have effect on the preview, that is correct when is in portrait, but is simply rotate in landscape 'cause the camera don't rotate itself, but just place the portrait image rotated. 正如您所看到的,
parameters.setRotation()
对预览没有影响 ,这在纵向时是正确的,但只是在横向旋转,因为相机不会自行旋转,而只是旋转纵向图像。
So, is there a way to show a camera preview in landscape when the app is in portrait? 那么,当应用程序处于纵向状态时,有没有办法在横向显示相机预览?
Thanks. 谢谢。
Check out this method to set orientation of camera. 查看此方法以设置相机的方向。 The parameter
orientation
is Display.getRotation(), you could change set it as per your requirement.: 参数
orientation
是Display.getRotation(),您可以根据您的要求更改设置:
public void setCameraOrientation(int orientation) {
int orientationDegree = 0;
switch (orientation) {
case Surface.ROTATION_0:
orientationDegree = 0;
break;
case Surface.ROTATION_90:
orientationDegree = 90;
break;
case Surface.ROTATION_180:
orientationDegree = 180;
break;
case Surface.ROTATION_270:
orientationDegree = 270;
break;
}
int displayOrientation = (cameraInfo.orientation - orientationDegree + 360) % 360;
camera.setDisplayOrientation(displayOrientation);
Camera.Parameters parameters = camera.getParameters();
parameters.setRotation(displayOrientation);
camera.setParameters(parameters);
}
For the whole context check out my camera demo app here . 对于整个范围内检查出我的相机演示应用程序在这里 。 Specifically
CameraPreview
class. 特别是
CameraPreview
类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.