Skip to content

Instantly share code, notes, and snippets.

@joernroeder
Last active August 29, 2015 14:27
Show Gist options
  • Save joernroeder/ef746c5c6d174eedde34 to your computer and use it in GitHub Desktop.
Save joernroeder/ef746c5c6d174eedde34 to your computer and use it in GitHub Desktop.
ScreenCapture processing example based on the solution from https://github.com/onformative/ScreenCapturer/issues/2#issuecomment-59645559
import java.awt.Robot;
import java.awt.Rectangle;
import java.awt.AWTException;
class SimpleScreenCapture {
Robot robot;
PImage screenshot;
SimpleScreenCapture() {
try {
robot = new Robot();
}
catch (AWTException e) {
println(e);
}
}
PImage get() {
return this.get(0, 0);
}
PImage get(int x, int y) {
return this.get(x, y, width, height);
}
PImage get(int x, int y, int w, int h) {
return new PImage(robot.createScreenCapture(new Rectangle(x, y, w, h)));
}
}
SimpleScreenCapture simpleScreenCapture;
void setup() {
size(600, 400);
simpleScreenCapture = new SimpleScreenCapture();
}
void draw() {
image(simpleScreenCapture.get(), 0, 0, width, height);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment