Java Screenshot 螢幕擷取程式


public class Screenshot {
public static void main(String[] args) throws Exception {
args = new String[2];
args[0] = "3";
args[1] = "C:/Temp/t.jpg";

if (args.length != 2) {
System.err.println("Usage: java Screenshot WAITSECONDS OUTFILE.jpg");
System.exit(1);
}
//檢查是否傳入參數
String outFileName = args[1];
if (!outFileName.toLowerCase().endsWith(".jpg")) {
System.err.println("Error: output file name must end with \".jpg\".");
System.exit(1);
}
// wait
try {
long time = Long.parseLong(args[0]) * 1000L;
System.out.println("Waiting " + (time / 1000L) + " second(s)...");
Thread.sleep(time);
} catch(NumberFormatException nfe) {
System.err.println(args[0] + " does not seem to be a valid number of seconds.");
System.exit(1);
}
// determine current screen size
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
Rectangle screenRect = new Rectangle(screenSize);
// create screen shot
Robot robot = new Robot();

for(int i=0;i<108;i++){
screenRect.x = 118;
screenRect.y = 62;
screenRect.width = 841; // 1682;
screenRect.height = 1118;
BufferedImage image = robot.createScreenCapture(screenRect);
ImageIO.write(image, "jpg", new File(outFileName.replace("t.jpg", (i*2)+".jpg"))); //存為JPG影像檔

screenRect.x = 118+841;
screenRect.y = 62;
screenRect.width = 841; // 1682;
screenRect.height = 1118;
image = robot.createScreenCapture(screenRect);
ImageIO.write(image, "jpg", new File(outFileName.replace("t.jpg", (i*2+1)+".jpg"))); //存為JPG影像檔

toolkit.beep();
// give feedback
System.out.println("Saved screen shot (" + image.getWidth() + " x " + image.getHeight() + " pixels) to file \"" + outFileName + "\".");
Thread.sleep(3000);
}
}
}

廣告

About fenjj

Perfect !!??...
本篇發表於 Uncategorized。將永久鏈結加入書籤。

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

您的留言將使用 WordPress.com 帳號。 登出 / 變更 )

Twitter picture

您的留言將使用 Twitter 帳號。 登出 / 變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 / 變更 )

Google+ photo

您的留言將使用 Google+ 帳號。 登出 / 變更 )

連結到 %s