java程序截屏
来源:互联网 发布:实用网站 知乎 编辑:程序博客网 时间:2024/05/11 04:36
//返回的是截图生成的名称
public String snapShot(HttpServletRequest request) throws Exception{
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
BufferedImage screenshot = (new Robot()).createScreenCapture(new Rectangle
(0,0,(int)d.getWidth(),(int)d.getHeight()));
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
String str = sdf.format(date);
String fileName;
String defaultName="截屏";
String imageFormat;
String defaultImageFormat="jpg";
fileName=defaultName;
imageFormat=defaultImageFormat;
String name = fileName+str+"."+imageFormat;
String savePath = “”保存的路径“”
System.out.println(savePath);
File file = new File(savePath);
if(!file.isDirectory() && !file.exists()){
System.out.println("目录或文件开始创建");
file.mkdir();
}
String filePath = savePath +"\\"+ name;
System.out.println(filePath);
File f = new File(filePath);
ImageIO.write(screenshot, imageFormat, f);
return name;
}
public String snapShot(HttpServletRequest request) throws Exception{
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
BufferedImage screenshot = (new Robot()).createScreenCapture(new Rectangle
(0,0,(int)d.getWidth(),(int)d.getHeight()));
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
String str = sdf.format(date);
String fileName;
String defaultName="截屏";
String imageFormat;
String defaultImageFormat="jpg";
fileName=defaultName;
imageFormat=defaultImageFormat;
String name = fileName+str+"."+imageFormat;
String savePath = “”保存的路径“”
System.out.println(savePath);
File file = new File(savePath);
if(!file.isDirectory() && !file.exists()){
System.out.println("目录或文件开始创建");
file.mkdir();
}
String filePath = savePath +"\\"+ name;
System.out.println(filePath);
File f = new File(filePath);
ImageIO.write(screenshot, imageFormat, f);
return name;
}
阅读全文
1 0
- java截屏程序
- java程序截屏
- java实现截屏程序
- JAVA截屏程序(第二版)
- JAVA截屏程序(第四版)
- java程序截屏黑屏的现象
- java抓屏程序
- java 程序 生子程序
- jAVA程序
- java程序
- JAVA程序
- java 程序
- java程序..
- JAVA程序
- java程序
- Java程序
- java程序
- Java程序
- linux系统mysql数据库基本命令
- Cuckoo for Hashing--关于哈希表的练习
- 关于使用c# Sqlite的问题
- shell脚本--if判断(数字条件、字符串条件)
- 支付密码的效果
- java程序截屏
- Junit4单元测试 (一) 基本使用
- 安装 python/pip/numpy/matplotlib
- JavaScript 缓冲动画代码样例
- Docker 启动时报错:iptables:No chain/target/match by the name
- C#封装 继承 多态
- 决策树-泰坦尼克号生还预测
- python学习日记
- 浅谈为什么有反码和补码