Screen Capturer library for Processing

2012
Processing ScreenCapturer Library
The ScreenCapturer library for Processing enables you to capture any part of your screen and include this capture into your Processing sketch as image or video.
Probably everybody has experienced how complicated it might be to work with video in Processing, especially if you want to import a lot of different videos for testing purposes. You need to take care of the resolution, the codec and the size of the video file, in order to make it suit your specific requirements. Furthermore you might not even have access to a video or image file at all and just want to test some media in your sketch. That’s where the Processing ScreenCapturer library comes in quite handy.
The ScreenCapturer library for Processing enables you to capture any part of your screen and include this capture into your Processing sketch as image or video. This way you can try out video or image input in your Processing sketch without having to change the video/image import lines in your source code and don’t have to worry about problems regarding resolution, codec etc. Using this tool you can simply play a video in your browser or from your hard drive and move the ScreenCapturer window on top of your video and access everything inside this window frame from your Processing sketch. ScreenCapturer also allows you to take screenshots of certain areas of your desktop at stated intervals that could be useful for time laps videos for example.

The following example shows you how easy it is to load your captured image or video in your processing sketch with just some lines of code.

processing code

01
02
03
04
05
06
07
08
09
10
11
import com.onformative.screencapturer.*;
ScreenCapturer capturer;

void setup() {
size(500, 500);
capturer = new ScreenCapturer(width, height, 30); // 30 = framerate of the capture
}

void draw() {
image(capturer.getImage(), 0, 0);
}

The fact that you can easily recapture and manipulate a captured image allows you to create optical feedback and interface glitches.
So far the library is working on Windows and Mac OS- because of some internal Java problems a Linux version seems not to be possible at the moment. Contact us, if you want to contribute the Linux version.
List of all methods of the library:

ScreenCapturer(int width, int height, float frameRate);

ScreenCapturer(int width, int height, int xPos, int yPos, float frameRate);

PImage getImage();

PImage getOriginalImage();

void setVisible(boolean true);
void setSize(int width, int height);
void setAlwaysOnTop(boolean isOnTop);
void setLocation(int x, int y);

boolean isVisible();
int getWidth();
int getHeight();
boolean isAlwaysOnTop();
java.awt.Point getLocation();
Initializes the ScreenCapturer with the desired width, height and frameRate
Initializes the ScreenCapturer with width, height, x position, y position and desired frameRate

Returns a PImage of the current capture, resized to the dimension you set in the constructor
Returns a PImage of the current capture, with the current dimension of the capturer window
Sets the frame of the capturer visible or invisible
Sets the size of the capturer area
Sets if the window is always on top.
Sets the location of the capture window

Returns true of the capture window is set visible and vice versa
Returns the current width of the captured area
Returns the current height of the captured area
Returns if the window is set to always on op
Returns the current location of the capture window relative to your desktop coordinates. The location can be accessed though the .x and .y fields of the returned java.awt.Point