Issue
Is there a way to query the available camera resolutions using CameraX
? With Camera2
this is possible using rel="noreferrer">StreamConfigurationMap.getOutputSizes(). However, I can't find a way to do this using CameraX
.
It doesn't help that the documentation is quite outdated. Currently it references version 1.0.0-alpha06
and many APIs have changed in the latest 1.0.0-beta01
.
EDIT:
There is a way to get the available resolutions using Camera2
APIs (thanks to Wasim's answer below). However, that's only possible after the camera is bound to the lifecycle and therefore the target resolution cannot be changed anymore, which makes it quite useless.
Sure I can specify the target resolution without knowing the available ones but this way I have no control over the resulted aspect ratio. In my case, I end up with a 16:9 Preview
and a 4:3 ImageAnalysis
although the targetResolution
for my ImageAnalysis
is in 16:9 (224x126).
For the record, this is how you could get the output sizes:
val camera = cameraProvider.bindToLifecycle(this, cameraSelector, preview, imageAnalyzer)
val cameraId = Camera2CameraInfo.extractCameraId(camera.cameraInfo)
val cameraManager = context.getSystemService(Context.CAMERA_SERVICE) as CameraManager
val characteristics = cameraManager.getCameraCharacteristics(cameraId)
val streamConfigurationMap = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP)
val outputSizes = streamConfigurationMap.getOutputSizes(format)
Still looking for an actual solution. Thanks in advance.
Solution
You can always use camera2 api StreamConfigurationMap.getOutputSizes() to get supported resolution even in CameraX. As CameraX is build on top of camera2 it shouldn't matter.
if you want to know what resolution are supported by camerax, there isn't any API. But you can always set resolution of your choice and cameraX will take care of scaling it to nearest supported resolution.
Answered By - Wasim Ansari
Answer Checked By - David Marino (JavaFixing Volunteer)