title: Android Camera2 API set custom Brightness, Contrast, Gamma
body: <p>Since <strong><a href="https://stackoverflow.com/q/35354363/3226984">this</a></strong> hasn't clear answer, and stackoverflow hasn't questions / answers about Camera 2 API Gamma, I ask for solution to modify Brightness, Contrast and Gamma using <a href="https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html" rel="nofollow noreferrer">Android Camera 2 API</a>.<br>
  My code to get <strong><a href="https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html#CONTROL_AE_COMPENSATION_RANGE" rel="nofollow noreferrer">range</a></strong> and <strong><a href="https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html#CONTROL_AE_COMPENSATION_STEP" rel="nofollow noreferrer">step</a></strong>:</p>
  <pre><code>Rational controlAECompensationStep = characteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_STEP);
  if (controlAECompensationStep != null) {
      compensationStep = controlAECompensationStep.doubleValue();
  }
  
  Range&lt;Integer&gt; controlAECompensationRange = characteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE);
  if (controlAECompensationRange != null) {
      minCompensationRange = controlAECompensationRange.getLower();
      maxCompensationRange = controlAECompensationRange.getUpper();
  }
  </code></pre>
  <p>My method to set <strong>Brightness in percents</strong>:</p>
  <pre><code>public void setBrightness(int value) {
      int brightness = (int) (minCompensationRange + (maxCompensationRange - minCompensationRange) * (value / 100f));
      previewRequestBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, brightness);
      applySettings();
  }
  private void applySettings() {
      try {
          captureSession.setRepeatingRequest(previewRequestBuilder.build(), null, null);
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  <p>But this approach doesn't work correctly. Image becomes <a href="https://www.dropbox.com/s/xelc71a72qkoipp/20170321_095250.png?dl=0" rel="nofollow noreferrer">green</a>, like <a href="https://stackoverflow.com/q/35439159/3226984">here</a>.</p>
  <hr />
  <p>I described all what I found in <strong><a href="https://drive.google.com/open?id=19BJNgWeAfy1BvgDOF_Kp8WyjMkvSwSpNDvHanK7jE2s" rel="nofollow noreferrer">documentation</a></strong>.</p>