JAVA截取屏幕
来源:互联网 发布:汉代疆域 知乎 编辑:程序博客网 时间:2024/05/12 11:48
From:http://blog.csdn.net/lip009/article/details/1537797
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 javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JDesktopPane;
import java.sql.*;
/*******************************************************************
* 该JavaBean可以直接在其他Java应用程序中调用,实现屏幕的"拍照"
* This JavaBean is used to snapshot the GUI in a
* Java application! You can embeded
* it in to your java application source code, and us
* it to snapshot the right GUI of the application
* @see javax.ImageIO
* @author liluqun ([email]liluqun@263.net[/email])
* @version 1.0
*
*****************************************************/
public class GuiCamera {
private String fileName; //文件的前缀
private String defaultName = "GuiCamera";
static int serialNum = 0;
private String imageFormat; //图像文件的格式
private String defaultImageFormat = "jpg";
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
/****************************************************************
* 默认的文件前缀为GuiCamera,文件格式为PNG格式
* The default construct will use the default
* Image file surname "GuiCamera",
* and default image format "png"
****************************************************************/
public GuiCamera() {
fileName = defaultName;
imageFormat = defaultImageFormat;
}
/****************************************************************
* @param s the surname of the snapshot file
* @param format the format of the image file,
* it can be "jpg" or "png"
* 本构造支持JPG和PNG文件的存储
****************************************************************/
public GuiCamera(String s, String format) {
fileName = s;
imageFormat = format;
}
/****************************************************************
* 对屏幕进行拍照
* snapShot the Gui once
****************************************************************/
public void snapShot() {
try {
//拷贝屏幕到一个BufferedImage对象screenshot
BufferedImage screenshot = (new Robot())
.createScreenCapture(new Rectangle(0, 0,
(int) d.getWidth(), (int) d.getHeight()));
serialNum++;
//根据文件前缀变量和文件格式变量,自动生成文件名
String name = fileName + String.valueOf(serialNum) + "."
+ imageFormat;
File f = new File(name);
System.out.print("Save File " + name);
//将screenshot对象写入图像文件
ImageIO.write(screenshot, imageFormat, f);
System.out.print("..Finished! ");
} catch (Exception ex) {
System.out.println(ex);
}
}
public static void main(String[] args) {
System.out.print("打开连接");
GuiCamera cam = new GuiCamera("d:/Hello", "jpg");//
cam.snapShot();
}
}
- JAVA截取屏幕
- JAVA截取屏幕
- Java 屏幕截取程序
- JAVA截取屏幕
- Java屏幕截取全屏
- JAVA实现屏幕截取
- 【Java技术点】Java屏幕截取
- 通过java几行代码截取屏幕
- java实现截取屏幕保存为图片
- 屏幕截取
- 屏幕截取
- 屏幕截取
- Android中用java截取当前屏幕的功能
- 用Java Robot实现屏幕截取、远程监控
- iOS截取屏幕(屏幕截图)
- C#截取屏幕↑
- 如何进行屏幕截取
- C#截取计算机屏幕
- N进制数转换为十进制数
- STL 整理(map、set、vector、list、stack、queue、deque、priority_queue)
- 黑马程序员——银行业务调度系统
- 浅谈 struts2+ajax
- apache 整合 tomcat
- JAVA截取屏幕
- mysql的root用户密码丢失解决办法
- 【Unity3D】【NGUI】渐变label
- 获得Android设备的唯一序列号(一)
- C++0x中的委托构造函数(类似Java的构造条用构造)
- Exercise 3.2
- 入门HTML之2.8
- 网易面试题---来源于网络
- 使用事件驱动模型实现高效稳定的网络服务器程序