博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java 调用截图功能
阅读量:7088 次
发布时间:2019-06-28

本文共 2037 字,大约阅读时间需要 6 分钟。

hot3.png

最近刚发现,使用Java截图功能+三维地图,可以完成批量化数据处理的工作。

 Java

package com.thinkgem.jeesite.modules.skyline.web;import java.awt.Dimension;import java.awt.Rectangle;import java.awt.Robot;import java.awt.Toolkit;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import java.text.SimpleDateFormat;import java.util.Date;import javax.imageio.ImageIO;public class photo {	public static void main(String[] args) throws IOException {		Date dt=new Date();        SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd");        SimpleDateFormat sdf1=new SimpleDateFormat("yyyyMMddHHmmss");        String data=sdf.format(dt);        String rd=sdf1.format(dt);        try {            captureScreen("D:\\DevelopeSoft\\skylineTest\\"+data,rd+".png");        } catch (Exception e) {            // TODO Auto-generated catch block            e.printStackTrace();        }	}		public static void captureScreen(String fileName, String folder) throws Exception {		         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();//      Rectangle screenRectangle = new Rectangle(screenSize.width/2-200,screenSize.height/2-200,400,400);        // 0,60,1480,900        // x起点,y起点,截图长度,截图宽度        Rectangle screenRectangle = new Rectangle(290,60,900,900);        Robot robot = new Robot();        BufferedImage image = robot.createScreenCapture(screenRectangle);        // 截图保存的路径         File screenFile = new File(fileName);            // 如果路径不存在,则创建          if (!screenFile.getParentFile().exists()) {              screenFile.getParentFile().mkdirs();          }         //判断文件是否存在,不存在就创建文件        if(!screenFile.exists()&& !screenFile .isDirectory()) {            screenFile.mkdir();        }                File f = new File(screenFile, folder);                ImageIO.write(image, "png", f);        //自动打开        /*if (Desktop.isDesktopSupported()                 && Desktop.getDesktop().isSupported(Desktop.Action.OPEN))                    Desktop.getDesktop().open(f);*/    }}

 

转载于:https://my.oschina.net/discussjava/blog/1586481

你可能感兴趣的文章
Spark(Framework)
查看>>
用webgl打造自己的3D迷宫游戏
查看>>
微信小程序学习路线【经验之谈】
查看>>
android定位和地图开发实例
查看>>
Angular1.0和vue的区别
查看>>
通过ssh传输文件
查看>>
mac php solr扩展安装
查看>>
win32gui中操作任务栏托盘区的函数
查看>>
Struts2 漏洞分析及如何提前预防
查看>>
Python Pandas merge 的使用
查看>>
SVN版本库的迁移
查看>>
gRPC Windows编译应用
查看>>
设置 Linux 的 LD_LIBRARY_PATH 变量
查看>>
内核中的链表彻底分析与运用
查看>>
C#线程运行的机制和原理
查看>>
ecshop 导入自定义css
查看>>
Linux常用命令
查看>>
新版TeamTalk完整部署教程
查看>>
java实现泛域名解析,附SpringMVC源码示例
查看>>
mysql 导出 csv格式数据
查看>>