Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does zoomRatio display the error Unresolved reference when I use camerax "1.0.0-alpha06"?

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 enter image description here

like image 651
HelloCW Avatar asked Jan 07 '20 01:01

HelloCW


1 Answers

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

like image 140
LaurentP22 Avatar answered Sep 20 '22 15:09

LaurentP22