Created
November 4, 2013 02:45
-
-
Save jmpinit/7297387 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.*; | |
import java.awt.image.*; | |
import java.awt.event.KeyEvent; | |
Robot player; | |
BufferedImage capture = null; | |
PImage converted = null; | |
void setup() { | |
size(400, 350); | |
converted = new PImage(width, height, PConstants.ARGB); | |
try { | |
player = new Robot(); | |
} catch(Exception e) { println(e.toString()); } | |
} | |
void init() { | |
// trick to make it possible to change the frame properties | |
frame.removeNotify(); | |
// comment this out to not have the window "float" | |
frame.setAlwaysOnTop(true); | |
frame.setResizable(true); | |
frame.addNotify(); | |
super.init(); | |
} | |
void draw() { | |
try { | |
Point winloc = frame.getLocation(); | |
Rectangle screenRect = new Rectangle(winloc.x+frame.getWidth(), winloc.y, frame.getWidth(), frame.getHeight()); | |
capture = player.createScreenCapture(screenRect); | |
capture.getRGB(0, 0, converted.width, converted.height, converted.pixels, 0, converted.width); | |
converted.updatePixels(); | |
image(converted, 0, 0); | |
rectMode(CENTER); | |
} catch(Exception e) { println(e.toString()); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment