I have some code that can take a screenshot of the desktop to get my an image, My goal is to have a program that will take specific screenshots of specific programs, and I'm wondering if there is a way to get the dimensions and locations of specific windows/programs, im looking through java.awt and wondering if im looking in the correct locations.
public class Screenshot {
public static BufferedImage capture;
public static void main(String[] args){
File outputfile = new File("saved2.png");
Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
try {
capture = new Robot().createScreenCapture(screenRect);
} catch (AWTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Writes out to a file
// https://docs.oracle.com/javase/tutorial/2d/images/saveimage.html
try {
ImageIO.write(capture, "png", outputfile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.print("Screenshot captured");
}
}