我想在我的MacOS中截取某些應用程序的屏幕截圖,即使在另一個虛擬屏幕上而不是在活動屏幕中。MacOS中某些應用程序的Java屏幕截圖
我可以用下面的代碼捕獲活動屏幕,但是如何捕獲給定的應用程序?
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.imageio.ImageIO;
public class Screenshot {
public static void main(String args[]) throws AWTException, IOException {
while(true) {
String timeStamp = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date());
BufferedImage screencapture = new Robot().createScreenCapture(
new Rectangle(Toolkit.getDefaultToolkit().getScreenSize())
);
// Save as JPEG
File file = new File("./screens/screencapture" + timeStamp + ".jpg");
ImageIO.write(screencapture, "jpg", file);
try {
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
你如何識別你想要捕獲的窗口? – MadProgrammer
@MadProgrammer不知道,可以在代碼中修復應用程序 –