import java.awt.AWTException;
import java.awt.Desktop;
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.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.filechooser.FileSystemView;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
public class Snapshot {
private static Toolkit toolkit;
private static Robot robot;
private static BufferedImage bufferedImage = null;
public static void shot() throws AWTException, IOException {
toolkit = Toolkit.getDefaultToolkit();
robot = new Robot();
Dimension screenDimension = toolkit.getScreenSize();
bufferedImage = robot.createScreenCapture(new Rectangle(screenDimension));
String path = String.valueOf(FileSystemView.getFileSystemView().getHomeDirectory());
//System.out.println(path);
SimpleDateFormat sdf = new SimpleDateFormat("yyyymmddHHmmss");
String name = sdf.format(new Date());
name = name+".jpg";
File file = new File(path +"\\"+ name);
OutputStream output = new FileOutputStream(file);
bufferedImage = bufferedImage.getSubimage(0, 0, screenDimension.width,screenDimension.height);
JPEGEncodeParam param = JPEGCodec.getDefaultJPEGEncodeParam(bufferedImage);
param.setQuality(0.7F, false);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(output, param);
encoder.encode(bufferedImage);
encoder.getOutputStream().close();
Desktop.getDesktop().open(new File(path));
Runtime.getRuntime().exec("cmd /c " + path + name);
}
public static void main(String[] args) throws AWTException, IOException {
shot();
}
}
分享到:
相关推荐
一个很是用的java截屏小类,适合初学者,有注释,希望对大家的学习有帮助。
用JAVA简单实现截屏
可用于Java截屏,对于屏幕上显示的任何信息均可以实时截取,包括图片和摄像头采集会的信息
Java截屏+图像处理,供大家一起共同分享学习。
java截屏程序
window截屏生成gif
JAVA截屏JAVA截屏JAVA截屏
java截屏小程序。支持png,jpg,gif三种图片类型。 附上源码。 线程控制。 支持配置文件。 支持全屏截图和部分截图。
Eclipse4.2.1编写的Java屏幕截屏工具,可以实现简单的方块区域截屏,截屏文件放在D盘。
java截屏小程序 附源码,不能登QQ的时候可以讲究下,jar格式的,运行鼠标框选截屏内容,右键点击保存或退出。java新手,望多指教
用Java编写,实现类似Windows下PrintScreen的截屏功能。
java 截屏工具
已经调通的java截屏软件,有详细说明,保存格式为png或jpg
html5 实现网页截屏 页面生成图片
java截屏工具,默认自动打开浏览器然后截屏,可以设置截屏的大小,并自动保存,亲测可以用,分项给大家试用。
QQ2010截屏单文件般 解压就能用 绿色版本 板刷功能可用
Java写的截屏工具(源代码) Java写的截屏工具(源代码)
自己写的一个截屏生成gif的软件,效果还不错 自己写的一个截屏生成gif的软件,效果还不错 自己写的一个截屏生成gif的软件,效果还不错 自己写的一个截屏生成gif的软件,效果还不错 喜欢的可以下载!~
用java robot 写得截屏源码,自己慢慢参考
对url网页进行截屏,生成图片,保存到本地磁盘中,绝对的JAVA代码哦