'How to get current Exposure for Camera2 API in android

In android.hardware.Camera old, I use code below get current Exposure and get it for Camera

Camera.Parameters param = mCamera.getParameters();
currentExposure += param.getExposureCompensationStep();
param.setExposureCompensation((int) currentExposure);
Timber.d("exposure:" + currentExposure);
mCamera.setParameters(param);

How to use it for Camera2 API new. Please. Help me!



Solution 1:[1]

  1. There must be a call captureSession.setRepeatingRequest(request, captureCallback, ...); in your code.
  2. CaptureResult instance is passed to this captureCallback.
  3. You can continuously get exposure (in nanoseconds) from CaptureResult via key CaptureResult.SENSOR_EXPOSURE_TIME.

Solution 2:[2]

Try this for Camera Characteristics.

mCameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_STEP);

Solution 3:[3]

 public void setExposure(double exposureAdjustment) {

        CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
        String[] cameraIds = new String[0];
        try {
            cameraIds = manager.getCameraIdList();
        } catch (CameraAccessException e) {
            e.printStackTrace();
        }
        CameraCharacteristics cameraCharacteristics = null;
        try {
            cameraCharacteristics = manager.getCameraCharacteristics(cameraIds[0]);
        } catch (CameraAccessException e) {
            e.printStackTrace();
        }
        requestBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
        requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
        Range<Integer> range1 = cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE );


        Log.d(TAG,"range1" +range1);

        Integer minExposure = range1.getLower();
        Log.d(TAG,"minExposure" +minExposure);

        Integer maxExposure = range1.getUpper();
        Log.d(TAG,"maxExposure" +maxExposure);


        if (minExposure != 0 || maxExposure != 0) {
            float newCalculatedValue = 0;
            if (exposureAdjustment >= 0) {
             
                newCalculatedValue = (float) (maxExposure * exposureAdjustment);


            } else {
              
                newCalculatedValue = (float) (minExposure  * exposureAdjustment);
            }

            if (requestBuilder != null) {
                 
                requestBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, (int) newCalculatedValue);


            }
        }
    }

Solution 4:[4]

Try this

Range<Long> range = mCameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_EXPOSURE_TIME_RANGE);

Solution 5:[5]

In camera 2 api you have to define camera manger

private android.hardware.camera2.CameraManager manager;

//better to add inside constructor
manager = (android.hardware.camera2.CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);

Next steps You can get camera characteristics like this

    for (String cameraId : manager.getCameraIdList()) {
         CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);

         //get camera mode
         Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);

         //getting Stream configuration 
         StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
        }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Denis
Solution 2 Dishonered
Solution 3 gopssays
Solution 4 tompadre
Solution 5