setTargetResolution return smallest image size on some xiaomi devices

Skip to first unread message
Assigned to by

Александр Борисович

Sep 20, 2023, 7:49:21 PMSep 20
to Android CameraX Discussion Group
We have a several devices. For my realme 6 next code return image size closest to 1200x720 and works well.

        ImageAnalysis imageAnalysis = new ImageAnalysis.Builder()
                .setTargetResolution(new Size(1200,720 ))

But on Xiaomi A1 and Redmi note 4 returned image size: 280x480
After replacing setTargetResolution to .setTargetAspectRatio(AspectRatio.RATIO_16_9) returned image size become  480x843.

How I can fix it for xiaomi devices?

Charcoal Chen

Sep 20, 2023, 9:53:42 PMSep 20
to Android CameraX Discussion Group, Alexandr Bor

I guess flipping the target resolution (new Size(720, 1200)) can resolve the problem. When using the legacy setTargetResolution() API, you might need to flip the size according to the target rotation value. Please see the following javadoc:
  • The resolution Size should be expressed in the coordinate frame after rotating the supported sizes by the target rotation. For example, a device with portrait natural orientation in natural target rotation requesting a portrait image may specify 480x640, and the same device, rotated 90 degrees and targeting landscape orientation may specify 640x480.
To avoid the same problem as this, we have introduced a new ResolutionSelector API and deprecated the original setTargetResolution and setTargetAspectRatio API. All settings for the new ResolutionSelector API refer to the sizes in the camera sensor coordinate which are exactly the same as what retrieved by StreamConfigurationMap#getOutputSizes() or the size that the ImageAnalysis's Analyzer will receive. It can also provide more settings to select the best resolution for your requirements. If possible, please have a try to the new ResolutionSelector API. The code might look like the following:

    ImageAnalysis imageAnalysis = new ImageAnalysis.Builder()
                    new ResolutionSelector.Builder()
                        new ResolutionStrategy(new Size(1200, 720), ResolutionStrategy.FALLBACK_RULE_CLOSEST_HIGHER_THEN_LOWER)

Reply all
Reply to author
0 new messages