• java进行屏幕截图


    myScreenShot.java
    import javax.imageio.ImageIO;
    import java.awt.*;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.util.UUID;
    
    import org.apache.logging.log4j.LogManager;
    import org.apache.logging.log4j.Logger;
    
    public class myScreenShot {
    
        public static void main(String[] args) throws AWTException{
            String fileName = "mypic";    //是个文件夹名字
            screenShot(fileName);
        }
    
        public static final Logger logger = LogManager.getLogger(myScreenShot.class);
    
    
        public static String screenShot(String fileName) {
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();//获取屏幕大小
            Rectangle screenRectangle = new Rectangle(screenSize);//根据屏幕大小创建一个矩形
            String randomName = UUID.randomUUID().toString().replace("-", "");
            String name = randomName + ".png";//jpg等也可
            // 截图保存的路径
            File screenFile = new File(fileName);
            if (!screenFile.exists()) {
                screenFile.mkdirs();//创建文件路径
            }
            Robot robot;
            String path = "";
            boolean b = false;
            try {
                robot = new Robot();
                BufferedImage image = robot.createScreenCapture(screenRectangle);//使用Robot类提供的截屏方法,
                File f = new File(screenFile, name);
                b = ImageIO.write(image, "png", f);
            } catch (Exception e) {
    
                logger.error("error : ", e);
            }
    
            if (b) {
                path = fileName + File.separator + name;
            }
            return path;
        }
    }
  • 相关阅读:
    pod
    jquery日历插件
    web前端常用api
    VUE.JS——脚手架安装
    github入门到上传本地项目
    appach修改默认端口之后数据库的访问
    在脚本中刷新impala元信息
    在脚本中刷新impala元信息
    不同hadoop集群之间迁移hive数据
    不同hadoop集群之间迁移hive数据
  • 原文地址:https://www.cnblogs.com/jingzaixin/p/16444566.html
Copyright © 2020-2023  润新知