We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey guys, I was wondering if processing could take pictures of my screen. How could I start this code? I want it to take a picture every millisecond. Thanks in advance.
Answers
If you mean canvas shots, a simple get() will do: https://processing.org/reference/get_.html
Thank you but I meant take a screen shot of my desktop as well. Whatever is on my desktop. Will saveFrame() work?
Processing is only about the canvas it provides. Anything else, we gotta find a library to do that! :(|)
I see, thank you for your time!
Every millisecond sounds a bit much, that's 1000 times per second. The following example shows you how to get a screenshot of the whole screen into a PImage that can be used and displayed in Processing. It takes a screenshot every 60th frame, so about once every second.
Note that taking screenshots of the screen that you display on, will result in a feedback loop! :-)
Code Example
Amnon thanks but what is java.awt , null, and how did we all of a sudden make a new Robot function? In line 15.
Like GoToLoop said, this isn't possible in Processing. But since Processing is Java, you have access to all the Java code / classes. All you have to do is add the relevant imports to the top of your sketch. In Java there happens to be a screen capture method in the Robot class, which was used in the example above.
Often when something is not possible in Processing or one of it's libraries, it is possible in Java or one it's libraries. For more info on the available classes in Java, see: https://docs.oracle.com/javase/7/docs/api/overview-summary.html
Most of the things in the screenshot() method are Java, not Processing. Null is (also) part of Processing however. It allows you to see if something valid is there. For example an object, a loaded image, font, etc. See: https://www.processing.org/reference/null.html Checking againt null is a safeguard for nullpointerexceptions.
@amnon's tweaked version w/ detailed library imports & cached pre-instantiations: :ar!