title: How can I freeze picture of camera with CameraX API in Android Studio?
body: <p>I'm learning CameraX API, and <a href="https://github.com/android/camera-samples/tree/master/CameraXBasic" rel="nofollow noreferrer">CameraXBasic</a> is a office sample code. </p>
  
  <p><em>CameraFragment.kt</em> in <em>CameraXBasic</em> displays a real camera preview, I hope to add a <em>Switch</em> button to  freeze current preview, by which the picture will not change even if I move mobile phone camera lens.</p>
  
  <p>How can I do with CameraX API? Thanks!</p>
  
  <p><strong>CameraFragment.kt</strong></p>
  
  <pre><code>private lateinit var viewFinder: TextureView
  
  private fun bindCameraUseCases() {
      // Get screen metrics used to setup camera for full screen resolution
      val metrics = DisplayMetrics().also { viewFinder.display.getRealMetrics(it) }
      val screenAspectRatio = Rational(metrics.widthPixels, metrics.heightPixels)
      Log.d(TAG, "Screen metrics: ${metrics.widthPixels} x ${metrics.heightPixels}")
  
      // Set up the view finder use case to display camera preview
      val viewFinderConfig = PreviewConfig.Builder().apply {
          setLensFacing(lensFacing)
          // We request aspect ratio but no resolution to let CameraX optimize our use cases
          setTargetAspectRatio(screenAspectRatio)
          // Set initial target rotation, we will have to call this again if rotation changes
          // during the lifecycle of this use case
          setTargetRotation(viewFinder.display.rotation)
      }.build()
  
      // Use the auto-fit preview builder to automatically handle size and orientation changes
      preview = AutoFitPreviewBuilder.build(viewFinderConfig, viewFinder)
  
   ....
  
   CameraX.bindToLifecycle(
              viewLifecycleOwner, preview, imageCapture, imageAnalyzer)
  }
  </code></pre>