Java Utililty Methods Screenshot

List of utility methods to do Screenshot

Description

The list of methods to do Screenshot are organized into topic(s).

Method

BufferedImageacquireScreenshot(Component component)
Makes a hardcopy image from the given component.
Rectangle rect = component.getBounds();
Insets insets = null;
if (component instanceof Window) {
    insets = ((Window) component).getInsets();
    rect.width -= insets.left + insets.right;
    rect.height -= insets.top + insets.bottom;
BufferedImage image = new BufferedImage(rect.width, rect.height, BufferedImage.TYPE_INT_RGB);
...
BufferedImagecapture()
capture
try {
    Robot robot = new Robot();
    Rectangle area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
    BufferedImage bufferedImage = robot.createScreenCapture(area);
    BufferedImage scaledImage = new BufferedImage(bufferedImage.getWidth() / 20,
            bufferedImage.getHeight() / 20, BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics2D = scaledImage.createGraphics();
    graphics2D.drawImage(bufferedImage, 0, 0, scaledImage.getWidth(), scaledImage.getHeight(), null);
...
voidcapture(final String fileName, final Rectangle rect)
capture current window.
final String name = fileName.toLowerCase().endsWith(".png") ? fileName : fileName.concat(".png");
try {
    final BufferedImage img = new Robot().createScreenCapture(rect);
    ImageIO.write(img, "png", new File(name));
} catch (final IOException | AWTException e) {
    e.printStackTrace();
BufferedImagecaptureAsScreenshot(final Frame frame)
Captures screenshot of component nd returns as BufferedImage.
BufferedImage bi = null;
try {
    Robot robot = new Robot();
    Rectangle bounds = getInternalRectangle(frame);
    bi = robot.createScreenCapture(bounds);
} catch (AWTException e) {
    e.printStackTrace();
return bi;
BufferedImagecaptureCurrentMonitor()
capture Current Monitor
Point cursor = MouseInfo.getPointerInfo().getLocation();
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] screens = ge.getScreenDevices();
Robot robot = null;
Rectangle bounds = null;
for (GraphicsDevice screen : screens) {
    bounds = screen.getDefaultConfiguration().getBounds();
    if (bounds.contains(cursor)) {
...
ListcaptureEachMonitor()
capture Each Monitor
List<BufferedImage> result = new ArrayList<BufferedImage>();
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] screens = ge.getScreenDevices();
for (GraphicsDevice screen : screens) {
    try {
        Robot robot = new Robot(screen);
        Rectangle screenBounds = screen.getDefaultConfiguration().getBounds();
        screenBounds.x = 0;
...
BufferedImagecaptureMainMonitor()
capture Main Monitor
Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
try {
    return new Robot().createScreenCapture(screenRect);
} catch (AWTException e) {
    e.printStackTrace();
return null;