0

I am working on creating a bot. What I need to do is find the color red, then click on it. I need to be able to use my function without saving a picture to my computer every half second. How can I use a picture of the screen without actually saving it?

strbry
  • 23
  • 6

1 Answers1

1

The java.awt.Robot class provides a useful method for capturing a screenshot.

BufferedImage createScreenCapture(Rectangle screenRect)

Once you have the image within the buffer you can perform other tasks on it like getting RGB color of the pixels within the image:

bufImg.getRaster().getPixel(x,y,outputChannels);

The following answer provides more info regarding that: java bufferedimage getting red green and blue individually.

Hope this helps you further.

Community
  • 1
  • 1
uniknow
  • 938
  • 6
  • 5
  • I'm a little confused on how to use the `BufferedImage createScreenCapture(Rectangle screenRect)`. If I want to save it to a variable `imageToSearch`, how would I do that? – strbry May 03 '16 at 04:12
  • The following [example](http://www.programcreek.com/java-api-examples/index.php?source_dir=fiji-master/src-plugins/CLI_/src/main/java/CLI/Screenshot.java) shows how the `createScreenCapture` can be used. Within this example the screen capture is saved to a file but that would be in your case not necessary. – uniknow May 03 '16 at 07:11