3

I'm currently working on Androids Camera 2 API and my current problem is, that I cannot set the CONTROL_AE_EXPOSURE_COMPENSATION.

I want to exposure between -2 to 2.

Here is my code.

public void setExposure(double exposureAdjustment) {
    Range<Integer> range1 = mCameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE);
    int minExposure = range1.getLower();
    int maxExposure = range1.getUpper();

    float newCalculatedValue = 0;
    if (exposureAdjustment >= 0) {
        newCalculatedValue = (float) (minExposure * exposureAdjustment);
    } else {
        newCalculatedValue = (float) (maxExposure * -1 * exposureAdjustment);
    }

    try {
        CaptureRequest captureRequest = mPreviewRequestBuilder.build();
        mPreviewSession.setRepeatingRequest(mPreviewRequest,
                mCaptureCallback, mBackgroundHandler);
        mPreviewRequestBuilder.set(captureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, (int) newCalculatedValue);
        mPreviewSession.capture(captureRequest, mCaptureCallback, mBackgroundHandler);

        Log.v("cascascasc", exposureAdjustment + " : " + newCalculatedValue);

    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

On Seekbar change listener i call

    exposure_seekbar.setMin(-2);
    exposure_seekbar.setMax(2);
    exposure_seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {

            if (b) {
                mCamera2Fragment.setExposure((double)i);
            }
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });
  • is there any exception which you can share? or other additional input? – Manuel Schmitzberger Nov 28 '18 at 09:50
  • No there is not any exception. But i am not able to visually check the exposure effect. –  Nov 28 '18 at 09:51
  • @ManuelSchmitzberger Can you please share your Java class file if your code working properly? –  Nov 28 '18 at 10:01
  • This [previeFragement](https://github.com/ManuelSchmitzberger/Camera2/blob/master/camera2/src/main/java/us/yydcdut/camera2/ui/PreviewFragment.java#L171) should work. So you only need to add your `setExposure(...)` and seekbar method. – Manuel Schmitzberger Nov 28 '18 at 10:08
  • Should I replace my _cameraFragment_ class with your _PreviewFragment_? If then will your code support aspect ratio for camera preview for all devices ?? –  Nov 28 '18 at 10:12
  • I don't know, how your project looks like. >If then will your code support aspect ratio for camera preview for all devices ??< should be, yes. – Manuel Schmitzberger Nov 28 '18 at 20:56
  • https://stackoverflow.com/a/52520356/549372 – Martin Zeitler Dec 10 '18 at 23:20
  • @MartinZeitler Is it the same as Exposure? As i know it just increase brightness in the link –  Dec 11 '18 at 06:58

0 Answers0