一、java代码
public class ScreenShot { public static void main(String args[]){ ScreenShot screenShot = new ScreenShot(); try { screenShot.captureScreen("D:\\pictures"); } catch (Exception e){ e.getMessage(); } } public void captureScreen(String path) throws Exception { //格式化图片名称 SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyddMMhhmmss", Locale.CHINESE); String name = simpleDateFormat.format(new Date()).toString()+".png" ; File dir = new File(path); if(!dir.exists()){ dir.mkdirs(); } File file = new File(path + "\\" + name); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();//获得屏幕高度和宽度 Rectangle screenRectangle = new Rectangle(screenSize);//指定一个坐标区域 Robot robot = new Robot(); BufferedImage image = robot.createScreenCapture(screenRectangle); ImageIO.write(image, "png", file); } }