source code snippet for screenshots across multiple monitors. Munge to
your own requirements
import java.awt.AWTException;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Properties;
import javax.imageio.ImageIO;
....
//read in user prefs for this screenshot
String path = "file/path/to/save/screenshot/to.extension";
Robot robot = new Robot();
// To support dual monitors, we need to do some funkiness
// all the screens we have
GraphicsDevice[] devices =
GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
// where we collect all the individual screenshots
BufferedImage[] images = new BufferedImage[devices.length];
int maxWidth = 0;
int maxHeight = 0;
// collect the screenshots. We will merge them from left to right
later
for (int i = 0; i < devices.length; i++) {
GraphicsDevice device = devices[i];
GraphicsConfiguration config = device.getDefaultConfiguration();
Rectangle bounds = config.getBounds();
BufferedImage image = robot.createScreenCapture(bounds);
if (image.getHeight() > maxHeight) {
maxHeight = image.getHeight();
}
maxWidth += image.getWidth();
images[i] = image;
}
//stitch the individual screenshots together into a single image.
All bottom aligned
BufferedImage merged = new BufferedImage(maxWidth, maxHeight,
BufferedImage.TYPE_INT_RGB);
int dx1 = 0;
for (int i = 0; i < images.length; i++) {
BufferedImage image = images[i];
merged.getGraphics().drawImage(image, dx1, 0, dx1 + image.getWidth
(), image.getHeight(), 0, 0,image.getWidth(), image.getHeight(),
null);
// ensure next image is offset to the right
dx1 += image.getWidth();
}
ImageIO.write(merged, org.codehaus.plexus.util.FileUtils.getExtension
(path).toUpperCase(), new File(path));
Regards,
Bert