简体   繁体   中英

Camera X android landscape orientation for preview

I have implemented a Camera X preview which handle both portrait an landscape orientation. 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.

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. To make things simpler, you can also use the CameraController API which creates the Preview class for you.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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