Android CameraX - manually change Exposure(Duration and ISO) and White Balance(Temperature and Tint)

Viewed 528

Iam using CameraX for my project. I have created preview useCase and image capture useCase.

 val cameraProviderFuture = ProcessCameraProvider.getInstance(requireActivity())

    cameraProviderFuture.addListener({
        // Used to bind the lifecycle of cameras to the lifecycle owner
        val cameraProvider: ProcessCameraProvider = cameraProviderFuture.get()
        val aspectRatio = aspectRatio()

        val preview = Preview.Builder()
            .setTargetAspectRatio(aspectRatio)
            .build()
            .also {
                it.setSurfaceProvider(binding.viewFinder.surfaceProvider)
            }

        val cameraSelector = CameraSelector.DEFAULT_BACK_CAMERA

        imageCapture = ImageCapture.Builder()
            .setTargetAspectRatio(aspectRatio)
            .build()

        try {
            // Unbind use cases before rebinding
            cameraProvider.unbindAll()
            // Bind use cases to camera
             camera = cameraProvider.bindToLifecycle(
                this, cameraSelector, preview, imageCapture)

        } catch(exc: Exception) {
            Log.e(TAG, "Use case binding failed", exc)
        }

    }, ContextCompat.getMainExecutor(requireActivity()))

Implemented Exposure in CameraX

 ExposureState exposureState = camera.getCameraInfo().getExposureState()

    if (!exposureState.isExposureCompensationSupported()) return

Range<Integer> range = exposureState.getExposureCompensationRange()

   if (range.contains(index)){
    camera.getCameraControl().setExposureCompensationIndex(index)}

How to implement ISO and White Balance (Temperature and Tint) in CameraX API?

0 Answers
Related