I have read the artical. https://proandroiddev.com/android-camerax-tap-to-focus-pinch-to-zoom-zoom-slider-eb88f3aa6fc6
I add Code A to the office camerx sample. https://github.com/android/camera-samples/tree/master/CameraXBasic
The sample code use camerax "1.0.0-alpha06"
I get the error Unresolved reference for zoomRatio, you can see Image 1, how can I fix it?
Code A
private fun setUpPinchToZoom() {
val cameraControl = CameraX.getCameraControl(lensFacing)
val cameraInfo = CameraX.getCameraInfo(lensFacing)
val listener = object : ScaleGestureDetector.SimpleOnScaleGestureListener() {
override fun onScale(detector: ScaleGestureDetector): Boolean {
val currentZoomRatio: Float = cameraInfo.zoomRatio.value ?: 0F
val delta = detector.scaleFactor
cameraControl.setZoomRatio(currentZoomRatio * delta)
return true
}
}
val scaleGestureDetector = ScaleGestureDetector(context, listener)
viewFinder.setOnTouchListener { _, event ->
scaleGestureDetector.onTouchEvent(event)
return@setOnTouchListener true
}
}
Image 1
Zoom controls have been added on version 1.0.0-alpha07. You need to update your code to use at least camera-Core version 1.0.0-alpha07: https://developer.android.com/jetpack/androidx/releases/camera
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With