I want to get max zoom value from every device before. set my zoom ratio in camera controler, how do i do that?
camera = cameraProvider.bindToLifecycle(
this, cameraSelector, preview, imageCapture, imageAnalyzer
)
val cameraControl = camera?.cameraControl
cameraControl?.setZoomRatio(7F)
setting a specific no doesn't help as max zoom value differ for different camera.
CodePudding user response:
You can get it by calling camera.cameraInfo.zoomState.maxZoomRatio
.
See: https://developer.android.com/reference/androidx/camera/core/CameraInfo#getZoomState()
CodePudding user response:
for anyone else who having the same issue. I'm leaving my code below.
val camera = cameraProvider.bindToLifecycle(
viewLifecycleOwner,
cameraSelector,
videoCapture,
preview
)
val cameraControl = camera.cameraControl
val cameraInfo =
camera.cameraInfo
val maxZoomRatio =
cameraInfo.zoomState.value?.maxZoomRatio// Set the default zoom level to the maximum zoom level supported by the camera
zoomRatio = maxZoomRatio?.times(1F.div(2F))
Log.d(TAG, "Max Zoom: $maxZoomRatio : $zoomRatio")
if (zoomRatio != null) {
cameraControl.setZoomRatio(zoomRatio!!)
}