1:1 Aspect Ratio in CameraX

karatuno :

I've been trying to use CameraX in my android application and wants both preview and output image to be a quality 1:1 Aspect Ratio image. I tried the following code for setting the image and preview config

PreviewConfig previewConfig = new PreviewConfig.Builder()
                .setTargetAspectRatio(new Rational(1, 1))
                .build();

--

        ImageCaptureConfig imageCaptureConfig = new ImageCaptureConfig.Builder()
                .setTargetAspectRatio(new Rational(1, 1))
                .setCaptureMode(ImageCapture.CaptureMode.MIN_LATENCY)
                .build();

According to the developer's guide this code would choose the best resolution the hardware could provide in that aspect ratio. Though this works well on some devices, on some devices the output image resolution is as low as 280X280 pixels. Seeming like that is not the valid aspect ratio for the hardware on that device.

What can I try as a workaround? What I had in mind was that I think every device would support 4:3 Aspect Ratio.

I can crop the output image but what about the preview. Can we crop the textureview?

Or can I put a simple black rectangle-shaped view on top of the viewfinder seeming like it is 1:1 image?

Alex Cohn :

You are not the only one to complain. 1:1 support is still not very good.

The mitigation you propose looks reasonable. 4:3 delivers high quality on all devices I have ever met. You can always overlay the preview with some non-transparent views to provide a look-and-feel of square preview.

There is an example on GitHub how you can use MediaCodec with cropped frames to produce a square video.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=309173&siteId=1