# Converting eyedropper's 'gray' value to RGB

**URL:** <https://forums.creativeclouddeveloper.com/t/converting-eyedroppers-gray-value-to-rgb/3503>\
**Category:** UXP Plugin API\
**Created:** [August 14, 2021, 6:16am UTC](https://forums.creativeclouddeveloper.com/t/converting-eyedroppers-gray-value-to-rgb/3503 "2021-08-14T06:16:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![blastframe](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/blastframe/32/1519_2.png) [@blastframe](https://forums.creativeclouddeveloper.com/u/blastframe)\
**Post date:** [August 14, 2021, 6:16am UTC](https://forums.creativeclouddeveloper.com/t/converting-eyedroppers-gray-value-to-rgb/3503/1 "2021-08-14T06:16:33Z")

</div>

Hello,  
I am listening to Photoshop’s `set` event for the Eye Dropper Tool. When using it with a Mask, it returns an object with the color mode `grayscale` and a value called `gray`. I need to convert this value to an RGB or Hex value.

For example, in the Color Panel, it says I have picked the gray color 50% which has an RGB value of ((149, 149, 149) and a Hex value of #959595.

I am unable to get the RGB & Hex values correctly. The formula I’m currently using is

```auto
let gray = parseInt(255-(255*obj.gray/100));

```

Using the above 50% example, `gray` is 49.8 and does not returning the correct result.

It works out as this…

```auto
gray = 255-(255*49.8/100)
gray = 255-(255*0.498)
gray = 255-126.99
gray = 128.01

```

128 is pretty far off from the RGB value of 149 shown in the Photoshop picker (that would be the correct value if the mode was HSB & B was 50%).

How can I convert the Photoshop eye dropper `gray` value to the same RGB/Hex Photoshop’s picker is showing?

 ![image](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/0/08cd821e8f1742363650e8c665bdd27d380856e2.jpeg)

Thank you!

---

<div class="post-metadata">

**Author:** ![blastframe](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/blastframe/32/1519_2.png) [@blastframe](https://forums.creativeclouddeveloper.com/u/blastframe)\
**Post date:** [August 14, 2021, 7:09am UTC](https://forums.creativeclouddeveloper.com/t/converting-eyedroppers-gray-value-to-rgb/3503/2 "2021-08-14T07:09:14Z")

</div>

Using the Alchemist plugin, I inspected the Application object and found a property called `foregroundColorRGB`. Here’s the code for getting it:

```auto
const get_fg_color = () => {
  const batchPlay = require("photoshop").action.batchPlay;
  const result = batchPlay(
  [
     {
        "_obj": "get",
        "_target": [
           {
              "_ref": "application",
              "_enum": "ordinal",
              "_value": "targetEnum"
           }
        ],
        "_options": {
           "dialogOptions": "dontDisplay"
        }
     }
  ],{
     "synchronousExecution": true,
     "modalBehavior": "fail"
  });
  return result[0].foregroundColorRGB;
}

```

It would be nice to know why the `gray` amount from the `set` event is different, but getting the RGB value after the FG color was set solved my issue.
