# How to set the proper color in Color Picker?

**URL:** <https://forums.unrealengine.com/t/how-to-set-the-proper-color-in-color-picker/304386>\
**Category:** Rendering\
**Tags:** color-picker, unreal-engine, color, question\
**Created:** [January 19, 2015, 1:46pm UTC](https://forums.unrealengine.com/t/how-to-set-the-proper-color-in-color-picker/304386 "2015-01-19T13:46:07Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![elliotek](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@elliotek](https://forums.unrealengine.com/u/elliotek)\
**Post date:** [March 25, 2015, 8:37pm UTC](https://forums.unrealengine.com/t/how-to-set-the-proper-color-in-color-picker/304386/14 "2015-03-25T20:37:13Z")

</div>

Hi guys,

I’ve coded a little function in googlescript (I think it’s javascript). It takes a string formated like this #FFFFFF, performs the appropriate conversion then outputs the corrected color in the same format.  
So you can feed it with a direct copy from the Photoshop color picker, then it outputs a string you can paste in the Unreal colorpicker.  
Here you go :

```
function sRGBConvert(val)
{
  val = val.toUpperCase();
  var r = 0;
  if(val.charCodeAt(1) > 60)
    r += (10 + val.charCodeAt(1)-65) * 16;
  else
    r += (val.charCodeAt(1)-48) * 16;

  if(val.charCodeAt(2) > 60)
    r += (10 + val.charCodeAt(2)-65);
  else
    r += (val.charCodeAt(2)-48);

  var g = 0;
  if(val.charCodeAt(3) > 60)
    g += (10 + val.charCodeAt(3)-65) * 16;
  else
    g += (val.charCodeAt(3)-48) * 16;

  if(val.charCodeAt(4) > 60)
    g += (10 + val.charCodeAt(4)-65);
  else
    g += (val.charCodeAt(4)-48);

  var b = 0;
  if(val.charCodeAt(5) > 60)
    b += (10 + val.charCodeAt(5)-65) * 16;
  else
    b += (val.charCodeAt(5)-48) * 16;

  if(val.charCodeAt(6) > 60)
    b += (10 + val.charCodeAt(6)-65);
  else
    b += (val.charCodeAt(6)-48);
  
  r /= 255.0;
  g /= 255.0;
  b /= 255.0;
  
  r = FixValue(r);
  g = FixValue(g);
  b = FixValue(b);
  
  r *= 255.0;
  g *= 255.0;
  b *= 255.0;
  
  val = "#";
  if((r>>4) > 9)
    val += String.fromCharCode((r>>4) + 65 - 10);
  else
    val += String.fromCharCode((r>>4) + 48);
  
  if((r % 16) > 9)
    val += String.fromCharCode((r % 16) + 65 - 10);
  else
    val += String.fromCharCode((r % 16) + 48);
  
  if((g>>4) > 9)
    val += String.fromCharCode((g>>4) + 65 - 10);
  else
    val += String.fromCharCode((g>>4) + 48);
  
  if((g % 16) > 9)
    val += String.fromCharCode((g % 16) + 65 - 10);
  else
    val += String.fromCharCode((g % 16) + 48);
  
  if((b>>4) > 9)
    val += String.fromCharCode((b>>4) + 65 - 10);
  else
    val += String.fromCharCode((b>>4) + 48);
  
  if((b % 16) > 9)
    val += String.fromCharCode((b % 16) + 65 - 10);
  else
    val += String.fromCharCode((b % 16) + 48);
  
  setActiveValue(val);  
}

function FixValue(val)
{
  if(val >= 0.04045)
    val = Math.pow((val + 0.055) / 1.055, 2.4);
  else
    val = val / 12.92;
  
  return val;
}
```

---

_[View the full topic](https://forums.unrealengine.com/t/how-to-set-the-proper-color-in-color-picker/304386)._
