Hi,
I’m looking for a way to take a screenshot of my desktop with all it’s open tabs while at the same time taking a picture with the build-in webcam. I would like to capture these 2 images automatically every 6 minutes.
Can you help me achieve this or point me in the right direction?
I am very new to processing, but looking forward to learning more!
Thanks!
Hi,
- To save a screenshot from Processing, there’s no built-in functions to do that. However you can use Java’s awt library as described in this forum post by @GoToLoop :
/**
* Robot Screenshots (v2.23)
* by Amnon (2014/Nov/11)
* mod GoToLoop
*
* Forum.Processing.org/two/discussion/8025/
* take-a-screen-shot-of-the-screen#Item_8
*/
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.AWTException;
PImage screenshot;
Rectangle dimension;
Robot robot;
void setup() {
size(1280, 720);
smooth(3);
frameRate(.5);
colorMode(RGB);
imageMode(CORNER);
background((color) random(#000000));
screenshot = createImage(displayWidth, displayHeight, ARGB);
dimension = new Rectangle(displayWidth, displayHeight);
try {
robot = new Robot();
}
catch (AWTException cause) {
println(cause);
exit();
}
}
void draw() {
image(grabScreenshot(screenshot, dimension, robot), 0, 0, width, height);
}
static final PImage grabScreenshot(PImage img, Rectangle dim, Robot bot) {
//return new PImage(bot.createScreenCapture(dim));
bot.createScreenCapture(dim).getRGB(0, 0
, dim.width, dim.height
, img.pixels, 0, dim.width);
img.updatePixels();
return img;
}
-
To read an image from the webcam, you need to use the video library. You can check out this example :
-
Then to save an image on the disk, you need to call the
PImage.save()
function on your image. -
Finally for the time, you can take a look at the
millis()
function that gives you the time in milliseconds since the beginning of the sketch.
Have fun!
1 Like