# How to find a colour on the screen?

**URL:** https://discourse.processing.org/t/how-to-find-a-colour-on-the-screen/30405
**Category:** Coding Questions
**Created:** [June 1, 2021, 5:31am UTC](https://discourse.processing.org/t/how-to-find-a-colour-on-the-screen/30405 "2021-06-01T05:31:31Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)
#### Post date: [June 1, 2021, 5:31am UTC](https://discourse.processing.org/t/how-to-find-a-colour-on-the-screen/30405/1 "2021-06-01T05:31:31Z")

</div>

i have a colour value (11, 96, 133) and i want the program to tell me if there is any colour that is really similar or exactly the same. here is the rest of my code if its useful:

```auto
PImage screenshot;
import java.awt.Robot;

void setup() {
 size(400,300);
}

void draw() {
     try {
       Robot robot = new Robot();
       screenshot = new PImage(robot.createScreenCapture(new java.awt.Rectangle()(0,0,screen.width,screen.height)));
     
     } catch (AWTException e) {
     }
 image(screenshot, 0, 0, width, height);
screenshot(0,0,width, height);
}

`

`

***1. > * Blockquote**

`

`

[quote="MoonAlien822, post:1, topic:30405, full:true"]
i have a colour value (11, 96, 133) and i want the program to tell me if there is any colour that is really similar or exactly the same. here is the rest of my code if its useful: 

PImage screenshot;
import java.awt.Robot;

void setup() {
 size(400,300);
}

void draw() {
     try {
       Robot robot = new Robot();
       screenshot = new PImage(robot.createScreenCapture(new java.awt.Rectangle()(0,0,screen.width,screen.height)));
     
     } catch (AWTException e) {
     }
 image(screenshot, 0, 0, width, height);
screenshot(0,0,width, height);
}

```

---

<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: [June 1, 2021, 5:55am UTC](https://discourse.processing.org/t/how-to-find-a-colour-on-the-screen/30405/2 "2021-06-01T05:55:57Z")

</div>

Hello,

Please format your code as per:  
[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)

This is the same code as you provided here:  
[https://discourse.processing.org/t/help-with-error-in-robot-class-and-createscreencapture-method/30396/1](https://discourse.processing.org/t/help-with-error-in-robot-class-and-createscreencapture-method/30396/1)

_ **I provided you with a link in the topic above to a working example that you can modify to get a PImage of the screen.** _

Please correct your code and then take the next step.

Once you get a PImage you can use get():  
[https://processing.org/reference/get\_.html](https://processing.org/reference/get_.html)

See tutorial:  
[https://processing.org/tutorials/pixels/](https://processing.org/tutorials/pixels/) _Intro To Image Processing_ section has a good example to work with!  
[https://processing.org/tutorials/color/](https://processing.org/tutorials/color/)

`:)`

---

<div class="post-metadata">

### Author: ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)
#### Post date: [June 1, 2021, 6:09am UTC](https://discourse.processing.org/t/how-to-find-a-colour-on-the-screen/30405/3 "2021-06-01T06:09:07Z")

</div>

i think i fixed it. if i need to change anything else, just say so and i will change it.

---

<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: [June 1, 2021, 6:29am UTC](https://discourse.processing.org/t/how-to-find-a-colour-on-the-screen/30405/4 "2021-06-01T06:29:05Z")

</div>

Hello,

> [@MoonAlien822](#):
>
> i think i fixed it.

You formatted your code but did not do it correctly.  
Take a look at it and you will see duplicate code… you can edit this.

> [@MoonAlien822](#):
>
> if i need to change anything else, just say so and i will change it.

That code does not work as is.  
Take a look at your code and examples for some insight.

I was able to find an exact color on the screen and display x,y co-ordinates with the tips that I provided you:

- Here is a working example that I already provided to get a screen image:  
_[Screen capture in Processing – Magic & Love Interactive](http://www.magicandlove.com/blog/2016/12/16/screen-capture-in-processing/)_  
This example should help you correct your code.  
This is just one example that I found and worked with.

- [https://processing.org/tutorials/pixels/](https://processing.org/tutorials/pixels/)  
_Intro To Image Processing_ section has a good example to work with!

This will require some work on your part to complete.

`:)`

---

<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: [June 1, 2021, 11:11am UTC](https://discourse.processing.org/t/how-to-find-a-colour-on-the-screen/30405/5 "2021-06-01T11:11:28Z")

</div>

Hello,

You can get the desktop screen resolution with this to integrate with the other code:  
[https://www.geeksforgeeks.org/java-program-to-print-screen-resolution/](https://www.geeksforgeeks.org/java-program-to-print-screen-resolution/)

The solution above was me doing some research.  
There may be other ways to do it.

Example:

```auto
// https://www.geeksforgeeks.org/java-program-to-print-screen-resolution/

import java.awt.*;

Dimension screenSize;
int scrWidth;
int scrHeight;
 
void setup() 
  {
  size(640, 480, P3D);
  
  // This does not work!
  //println(screen.width,screen.height);
  
  //Another solution
  screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  scrWidth = (int)(screenSize.getWidth());
  scrHeight = (int)(screenSize.getHeight());
  println("1: ", scrWidth, scrHeight);
  noLoop();
  }
 
void draw() 
  {
  println("2: ", scrWidth, scrHeight);
  }

```

And an _ **easier way** _:  
[https://processing.org/reference/size\_.html](https://processing.org/reference/size_.html)

makes reference to:

> As of Processing 3, to run a sketch at the full dimensions of a screen, use the **fullScreen()** function, rather than the older way of using **size(displayWidth, displayHeight)**.

You can use:

```auto
  // This does not work!
  //println(screen.width,screen.height);
  
  println(displayWidth, displayHeight);

```

I came across this looking here in some of the Processing source files:  
[https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java](https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java)  
Careful! You can get lost in there.

`:)`

---

<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: [June 1, 2021, 4:25pm UTC](https://discourse.processing.org/t/how-to-find-a-colour-on-the-screen/30405/6 "2021-06-01T16:25:06Z")

</div>

This post is continued here by @MoonAlien822 :

> [@How to check if the response from get is the same as color?](https://discourse.processing.org/t/how-to-check-if-the-response-from-get-is-the-same-as-color/30417):
>
> int x=1; int y=1; import java.awt.Robot; import java.awt.image.BufferedImage; import java.awt.Rectangle; color pas = color(11, 96, 133); //this is the color Robot robot; void setup() { size(1500, 3000); try { robot = new Robot(); } catch (Exception e) { println(e.getMessage()); } } void draw() { background(0); Rectangle r = new Rectangle(mouseX, mouseY, width, height); BufferedImage img1 = robot.createScreenCapture(r); PImage img2 = new PImage(img1); image(img2, 0, …

---

<div class="post-metadata">

### Author: ![MoonAlien822](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MoonAlien822](https://discourse.processing.org/u/MoonAlien822)
#### Post date: [June 30, 2021, 9:07am UTC](https://discourse.processing.org/t/how-to-find-a-colour-on-the-screen/30405/7 "2021-06-30T09:07:39Z")

</div>

thank you, do you know how you, insead of finding the exact colour, can find something extremely simelar?

---

<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: [June 30, 2021, 10:06am UTC](https://discourse.processing.org/t/how-to-find-a-colour-on-the-screen/30405/8 "2021-06-30T10:06:39Z")

</div>

Hello,

> [@MoonAlien822](#):
>
> insead of finding the exact colour, can find something extremely simelar?

I made some suggestions in your topic here:

> [@ScreenCapture with Robot Class (code not working)](https://discourse.processing.org/t/screencapture-with-robot-class-code-not-working/30551/7):
>
> thank you for your help. sadly it doesnt work because on different distances it has a different colour value and wont recognise it. but thanks anyway

I had success comparing to a range of hues.

`:)`
