capture Screen To Clip Board - Java Swing

Java examples for Swing:Screen

Description

capture Screen To Clip Board

Demo Code


import java.awt.AWTException;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import org.apache.log4j.Logger;

public class Main{
    private static final Logger logger = Logger.getLogger(ScreenUtil.class);
    public static boolean captureScreenToClipBoard() {
        try {//  w  w w  . ja  v a 2s  .c om
            Robot robot = null;
            try {
                robot = new Robot();
            } catch (final AWTException e) {
                logger.error("Could not get Robot");
                return false;
            }
            robot.keyPress(KeyEvent.VK_ALT);
            robot.keyPress(KeyEvent.VK_PRINTSCREEN);
            robot.keyRelease(KeyEvent.VK_PRINTSCREEN);
            robot.keyRelease(KeyEvent.VK_ALT);
            logger.debug("Screen captured into clipboard");
            return true;
        } catch (Exception e) {
            System.out.println(e);
            return false;
        }
    }
}

Related Tutorials