# Using. img.get to retrieve color values

**URL:** <https://discourse.processing.org/t/using-img-get-to-retrieve-color-values/31778>\
**Category:** Coding Questions\
**Created:** [August 18, 2021, 9:18am UTC](https://discourse.processing.org/t/using-img-get-to-retrieve-color-values/31778 "2021-08-18T09:18:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![glen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glen/32/14208_2.png) [@glen](https://discourse.processing.org/u/glen)\
**Post date:** [August 18, 2021, 9:18am UTC](https://discourse.processing.org/t/using-img-get-to-retrieve-color-values/31778/1 "2021-08-18T09:18:09Z")

</div>

I am using the following code

let c = img.get(xPos,yPos);

to sample a color from a pixel of an image and it works brilliantly as I can then fill or stroke with the variable (c)

My question is how do I then make (c) use the transparency value, too? As it stands I think it samples the RGB values … but i would like to add the 4th transparency value and be able to make it random

Any suggestions would be greatly appreciated

Glen

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [August 18, 2021, 11:02am UTC](https://discourse.processing.org/t/using-img-get-to-retrieve-color-values/31778/2 "2021-08-18T11:02:29Z")

</div>

Hello,

Start here and follow the trail of breadcrumbs (links):

[https://p5js.org/reference/#/p5/set](https://p5js.org/reference/#/p5/set)

`:)`

---

<div class="post-metadata">

**Author:** ![glen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glen/32/14208_2.png) [@glen](https://discourse.processing.org/u/glen)\
**Post date:** [August 18, 2021, 11:34am UTC](https://discourse.processing.org/t/using-img-get-to-retrieve-color-values/31778/3 "2021-08-18T11:34:07Z")

</div>

Perfect, thank you … after trundling through the rabbit hole I eventually came up with the following solution

let c = img.get(xPos,yPos);  
transcolor = color(c);  
noStroke();  
transcolor.setAlpha(50);  
fill(transcolor);

Thank you for saving a heap of time
