浏览 1839 次
锁定老帖子 主题:通过Robot截取屏幕事例
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-05-16
package com.wyh.io; 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; public class TestRobot implements Runnable { // 文件名 private String fileName; // 文件格式 private String imageFormat; //文件名序号 private static int incrmentNum = 1; public String getFileName() { return fileName; } public void setFileName(String fileName) { this.fileName = fileName; } public String getImageFormat() { return imageFormat; } public void setImageFormat(String imageFormat) { this.imageFormat = imageFormat; } public TestRobot() { } public TestRobot(String s, String format) { fileName = s; imageFormat = format; } // 截取桌面图象 public void startSnap(int i) { try { Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); // 通Robot获当前屏幕对象 BufferedImage screenshot = (new Robot()) .createScreenCapture(new Rectangle(0, 0, (int) dimension .getWidth(), (int) dimension.getHeight())); String name = fileName + incrmentNum + "." + imageFormat; ImageIO.write(screenshot, imageFormat, new File(name)); incrmentNum++; System.out.println("已经 保存线程 [" + i + "]" + " " + name); } catch (Exception ex) { System.out.println(ex); } } public void run() { System.out.println("开始截取......"); for (int i = 1;; i++) { this.startSnap(i); try { Thread.sleep(3800); } catch (Exception e) { e.printStackTrace(); } } } // test in main public static void main(String[] a) { TestRobot testRobot = new TestRobot("D:\\javaApp\\TestApp\\test", "jpg"); Thread thread = new Thread(testRobot); thread.start(); } } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |