# Get screen pixel color

**URL:** <https://forum.inductiveautomation.com/t/get-screen-pixel-color/45142>\
**Category:** Ignition\
**Tags:** ignition80, perspective\
**Created:** [March 31, 2021, 8:14pm UTC](https://forum.inductiveautomation.com/t/get-screen-pixel-color/45142 "2021-03-31T20:14:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![m.boog](https://avatars.discourse-cdn.com/v4/letter/m/f6c823/32.png) [@m.boog](https://forum.inductiveautomation.com/u/m.boog)\
**Post date:** [March 31, 2021, 8:14pm UTC](https://forum.inductiveautomation.com/t/get-screen-pixel-color/45142/1 "2021-03-31T20:14:55Z")

</div>

Hi All,  
Working in Perspective, Gateway 8.0.16.

I’m attempting to get the color of a pixel at the user’s mouse coordinates.

I found [this forum post](http://forum.inductiveautomation.com/t/map-regions-as-a-button/1409/5) from over a decade ago, which solved the problem in Vision with a few lines of Java.

Updating the original solution for Perspective, I put the following code in my view.root’s mouse OnClick event:

```auto
	import java.awt.Robot 
	robot = java.awt.Robot() 

	try:
		x = event.clientX
		y = event.clientY
		colour = robot.getPixelColor(x, y)
		
		system.perspective.print('Color: ' + str(colour))
	except Exception as e:
		system.perspective.print(str(e))

```

The code doesn’t error out, but it always prints  
`Color: java.awt.Color[r=0,g=0,b=0]`,  
even though the root is completely colored (not black). Anybody know if this solution should port over to Perspective, or another way to get color of a specific pixel?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [March 31, 2021, 8:42pm UTC](https://forum.inductiveautomation.com/t/get-screen-pixel-color/45142/2 "2021-03-31T20:42:04Z")

</div>

It does not. Someone would probably have to write a “Color Picker” component Module with the SDK to extend Perspective with this.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 31, 2021, 9:46pm UTC](https://forum.inductiveautomation.com/t/get-screen-pixel-color/45142/3 "2021-03-31T21:46:15Z")

</div>

You can’t use Java methods directly, and even in a Perspective module you’ll have a hard time doing this in a satisfactory way. You can only retrieve colors from HTML canvas elements, or images converted into canvas elements, it looks like; and even then, only from the same origin (due to browser security restrictions).  
A _potentially_ better option, but one highly dependent on your environment, would be a `color` input element, which might, depending on your browser + platform, have an eyedropper:  
[https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/color](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/color)  
But that would be very flakey, and requires a custom module as well.

---

<div class="post-metadata">

**Author:** ![m.boog](https://avatars.discourse-cdn.com/v4/letter/m/f6c823/32.png) [@m.boog](https://forum.inductiveautomation.com/u/m.boog)\
**Post date:** [March 31, 2021, 11:53pm UTC](https://forum.inductiveautomation.com/t/get-screen-pixel-color/45142/4 "2021-03-31T23:53:14Z")

</div>

Thanks for the help @pturmel and @paul-griffith.
