给大家嫖来一段截屏的代码(java原码)
来源:互联网 发布:外卖软件有哪些 编辑:程序博客网 时间:2024/05/16 06:02
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 javax.imageio.ImageIO;
/*******************************************************************
* 该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="png";
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!/n");
}
catch (Exception ex) {
System.out.println(ex);
}
}
public static void main(String[] args)
{
GuiCamera cam= new GuiCamera("d://Hello", "png");//
cam.snapShot();
}
}
- 给大家嫖来一段截屏的代码(java原码)
- 一段截屏的JAVA代码
- 一段JAVA截屏的代码
- 新人来喽!给大家看个简单的验证码小代码。
- 一段搜索地址的C代码【原】
- FindNextFile 蚊子132 给大家写一段通用的文件查找代码,非常简单明了
- 给一段下雪的代码。。。
- 一段代码(原)
- 一段大家熟悉的汇编代码分析
- 一段截屏的代码
- 给大家推荐一个LRU实现算法的java 代码
- 我只能给大家提供一段不同的经历
- 一段给人两种不同感觉的代码
- JAVA多线程的一段代码
- 一段神奇的Java代码
- 一段有意思的java代码
- 一段Java有意思的代码
- 关于一段游戏汇编代码的破解,求大家指点
- 微软Internet Explorer HTML解析 拒绝服务的漏洞
- log4j配置相对路径实现日志记录
- 转载:Windows中如何获取键盘和鼠标处于空闲状态的时间
- 集群文件系统的比较
- 用ASP.NET(VB)创建WINDOWS 2000/2003 SERVER站点
- 给大家嫖来一段截屏的代码(java原码)
- 什么是激情?怎样才算有激情?
- Max Plugin 综合症
- 测试...
- 嵌入式数据库系统Berkeley DB
- Java技术的最新发展蓝图
- Oracle数据库表范围分区策略测试过程
- 英特尔卖了通信与手机处理器,中国厂商是哭还是笑?
- 从排名看主流半导体厂商在3G市场的策略与心态