简体   繁体   English

相机 X android 横向预览

[英]Camera X android landscape orientation for preview

I have implemented a Camera X preview which handle both portrait an landscape orientation.我已经实现了一个 Camera X 预览,它可以同时处理纵向和横向。 Basics google params are good for portrait mode, but when I'm rotating my device the preview in landscape mode is broken the same as this question (see pic)基础谷歌参数适用于纵向模式,但是当我旋转我的设备时,横向模式下的预览与这个问题一样被破坏(见图)

          Preview preview = new Preview.Builder()
                                //.setTargetResolution(size)
                                //.setTargetAspectRatio(AspectRatio.RATIO_16_9)
                                .setTargetRotation(Surface.ROTATION_90)
                                .build();

I've tried all setter I found on SO and google camera doc like setTargetRotation and setTargetAspectRatio above, and also tried with matrix but nothing change in landscape.我已经尝试了我在 SO 和谷歌相机文档上找到的所有设置器,如上面的setTargetRotationsetTargetAspectRatio ,还尝试了矩阵,但景观没有任何变化。

How can I get more or less the same full screen preview in both orientation?如何在两个方向上获得或多或少相同的全屏预览?

Android camera preview transformation is a hard problem, that's why CameraX provides the PreviewView API for you. Android 相机预览转换是一个难题,这就是为什么 CameraX 为您提供PreviewView API。 To make things simpler, you can also use the CameraController API which creates the Preview class for you.为了使事情更简单,您还可以使用CameraController API 为您创建Preview class。

You can take a look at CameraX's test app for code samples: https://github.com/androidx/androidx/blob/androidx-main/camera/integration-tests/viewtestapp/src/main/java/androidx/camera/integration/view/CameraControllerFragment.java您可以查看 CameraX 的测试应用程序代码示例: https://github.com/androidx/androidx/blob/androidx-main/camera/integration-tests/viewtestapp/src/main/java/androidx/camera/integration /view/CameraControllerFragment.java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM