title: Camera2 API Set Custom White Balance & Temperature Color
body: <p>I'm trying to set a custom value for the White Balance &amp; temperature color in my camera app. I'm using camera2 API and I'm trying different ways to set this value. I found a method from a excel file to get the right RGB Temperature matrix [Red,Green,Blue] from the White Balance Value between 100 and 100.000. </p>
  
  <p>I attached this method to a Seekbar and its working fine, my problem appear when I try to focus something white, then it becomes pink. Any kind of light looks like a pink torch in the screen. </p>
  
  <p><a href="https://i.stack.imgur.com/vs1kD.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/vs1kD.jpg" alt="enter image description here"></a></p>
  
  <p>I'm setting the values in this way:</p>
  
  <pre><code>mPreviewRequestBuilder.set(CaptureRequest.COLOR_CORRECTION_MODE, CaptureRequest.COLOR_CORRECTION_MODE_TRANSFORM_MATRIX);
  
  RggbChannelVector rggb = getTemperatureVector(seekBackSelectedTemperature);
  
  mPreviewRequestBuilder.set(CaptureRequest.COLOR_CORRECTION_GAINS, myRggbChannelVector);
  </code></pre>
  
  <p>In other way, my method to get the matrix is this one:</p>
  
  <pre><code> public static RggbChannelVector getTemperatureVector (int WhiteBalanceValue){
  
  
      float InsertTemperature = WhiteBalanceValue;
      float temperature = InsertTemperature / 100;
      float red;
      float green;
      float blue;
  
      //Calculate red
  
      if (temperature &lt;= 66)
          red = 255;
      else {
          red = temperature - 60;
          red = (float) (329.698727446 * (Math.pow((double) red, -0.1332047592)));
          if (red &lt; 0)
              red = 0;
          if (red &gt; 255)
              red = 255;
      }
  
  
      //Calculate green
      if (temperature &lt;= 66) {
          green = temperature;
          green = (float) (99.4708025861 * Math.log(green) - 161.1195681661);
          if (green &lt; 0)
              green = 0;
          if (green &gt; 255)
              green = 255;
      } else
          green = temperature - 60;
      green = (float) (288.1221695283 * (Math.pow((double) red, -0.0755148492)));
      if (green &lt; 0)
          green = 0;
      if (green &gt; 255)
          green = 255;
  
  
      //calculate blue
      if (temperature &gt;= 66)
          blue = 255;
      else if (temperature &lt;= 19)
          blue = 0;
      else {
          blue = temperature - 10;
          blue = (float) (138.5177312231 * Math.log(blue) - 305.0447927307);
          if (blue &lt; 0)
              blue = 0;
          if (blue &gt; 255)
              blue = 255;
      }
      RggbChannelVector finalTemperatureValue = new RggbChannelVector(red/255,(green/255)/2,(green/255)/2,blue/255);
      return finalTemperatureValue;
  }
  </code></pre>
  
  <p>Maybe it's because the method of my CaptureRequest is not correct, but I don't find a way to fix it.</p>