Screen shot current active window in java

2.5k views Asked by At

Currently I am developing a project and it is a requirement that I screenshot the current active window on the screen (Assuming one monitor) and save it as an image.

I have worked at the following code which screenshots the entire screen:

int x = 0,y = 0;
Color suit = new Robot().getPixelColor(x, y);
Rectangle fs = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage rank = new Robot().createScreenCapture(fs);
ImageIO.write(rank, "bmp", new File("hi.bmp"));

and I am of the understanding that to get the size of the current active window one must use a method as such:

public static long getHWnd(Frame f) {
    return f.getPeer() != null ? ((WComponentPeer) f.getPeer()).getHWnd() : 0;
}

however I am having trouble implementing this method into my code, and I have no previous experience working with frames or rectangles.

Could I be pointed in the right direction in terms of where to go next! Thanks.

0

There are 0 answers