zoukankan      html  css  js  c++  java
  • Java截图小程序源码 IT

    Java编写的全屏截图小程序

     1 package cnom.test.testUtils;
     2 
     3 import java.awt.AWTException;
     4 import java.awt.Dimension;
     5 import java.awt.Rectangle;
     6 import java.awt.Robot;
     7 import java.awt.Toolkit;
     8 import java.awt.image.BufferedImage;
     9 import java.io.File;
    10 import java.io.IOException;
    11 
    12 import javax.imageio.ImageIO;
    13 
    14 /**
    15  * 显示器截图
    16  */
    17 
    18 public class LightScreen {
    19 
    20     private static String imageFormat = "png"; // 图像文件的格式
    21 
    22     private static String filePath = "D:/显示器截图/"; // 图像文件的生成路径
    23 
    24     public void snapShot(String format, String fileName) throws IOException, AWTException {
    25         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    26         Rectangle screenRectangle = new Rectangle(screenSize);
    27         Robot robot = new Robot();
    28         BufferedImage image = robot.createScreenCapture(screenRectangle);
    29         ImageIO.write(image, format, new File(fileName));
    30     }
    31 
    32     public static void main(String[] args) throws IOException, AWTException {
    33 
    34         LightScreen cam = new LightScreen();//
    35         String fileName = filePath + "截图." + imageFormat;
    36 
    37         cam.snapShot(imageFormat, fileName);
    38 
    39     }
    40 }
  • 相关阅读:
    第三节课 字符串拼接、格式化输出、深浅复制
    第四节课 集合、字典、运算符
    python-模块系列
    python正则表达式
    python第二天
    Python-第一天
    SQL SERVER 最近查询过的语句
    razor page 页面
    RAZOR显示表格数据
    邮件模板 C#
  • 原文地址:https://www.cnblogs.com/itfeng813/p/11646829.html
Copyright © 2011-2022 走看看