本以为用电脑考试,遂写了个后台自动截图保存,但没用上。
仅做记录。
一、截图的实现
public static void cutDownImpl() throws AWTException, IOException {
int count = 0;
//获取屏幕分辨率
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
//创建该分辨率的矩形对象
Rectangle screenRect = new Rectangle(d);
//创建一个robot对象
Robot robot = new Robot();
//根据这个矩形截图
while (true) {
BufferedImage bufferedImage = robot.createScreenCapture(screenRect);
//保存截图
File file = new File(ROOT + File.separator + count + SUFFIX);
ImageIO.write(bufferedImage, "jpg", file);
sleep(SLEEP);
count++;
}
}
二、延时函数
public static void sleep(int miles) {
try {
Thread.sleep(miles * 1000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
三、每20张图打包zip
if (count != 0 && count % BALE == 0) {
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(ROOT + File.separator + count + ZIP));
for (int i = count - BALE; i < count; i++) {
zos.putNextEntry(new ZipEntry(i + SUFFIX));
File f = new File(ROOT + File.separator + i + SUFFIX);
zos.write(toByteArray(new FileInputStream(f)));
zos.closeEntry();
f.delete();
}
zos.close();
} else