简体   繁体   English

当我的应用程序处于纵向状态时,请使用横向相机

[英]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.

相关问题 当我需要风景时,Kindle fire HD以纵向显示我的应用程序 - Kindle fire HD shows my app in portrait when i am requiring landscape Android Camera将图像返回为人像,使其变为风景? - Android Camera returns image as Portrait, getting it as landscape? Android应用程序不合理地旋转为横向,然后返回纵向 - Android app unjustifiably rotates to landscape and then back to portrait 从横向回到纵向时,为什么onSaveInstanceState无法正确保存我的EditText值 - Why isn't my onSaveInstanceState saving my EditText Value properly when going from landscape back to portrait 如何以编程方式将我的Android应用程序锁定为纵向/横向模式? - How can I lock my android app into portrait / landscape mode programatically? Android相机纵向拍摄风景照片 - Android camera taking landscape picture while on portrait orientation 在Android中横向或纵向播放Mediaplayer时会重新加载 - Mediaplayer reloads when going to landscape or to portrait in android 从横向/纵向旋转时,DatePickerDialog关闭 - DatePickerDialog closes when rotating from landscape/portrait 从纵向切换为横向时出错 - Error when switching from Portrait to Landscape ImageView 更改为纵向/横向时消失 - ImageView disapears when changing to portrait/landscape
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM