Hello. It has long been suffering with the removal of a screenshot from the screen (or from the application window).

I tried through .NET Graphics, as well as through Win api. Recently I started learning Java and decided to try using the built-in Java class Robot.

The result is the same everywhere - there is a screenshot, but it is not updated.

When you try to take a screenshot using Win api, the same screenshot is taken during the program operation.

When working with .NET [Graphics] and Java [Robot], the same screenshot is also taken, but it is updated when switching between windows. If the window is not switched, the screenshot will always be the same (as on the first attempt).

Can someone explain what the problem is and how to take screenshots normally, so that they are always different (what is happening on the screen or application now, and not what happened when you first took the screenshot).

    1 answer 1

    I don't know what doesn't work for you, but I have such code (in Java) and it works:

    public void screenshot(String filename) { try { Robot robot = new Robot(); String format = "jpg"; String filenameF = filename + "." + format; Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); BufferedImage screenFullImage = robot.createScreenCapture(screenRect); ImageIO.write(screenFullImage, format, new File(filenameF)); System.out.println("Скриншот сохранён!"); } catch (Exception ex) { System.err.println(ex); } } 
    • Saving the screenshot works great. But the same screenshot remains, although changes occur in the active window. It helps only to change the focus from the active window, after which, the original buffer is updated, but immediately freezes and the same screenshot starts again, only the one that was removed after updating the buffer. - Mikhail Tsaryov
    • @ Mikhail Tsarev I don’t know what is wrong with you, I sketched a simple program for taking screenshots with a button, and on the left in the background I opened a preview of the images, and every button click the picture was updated - NeoKat
    • I will clarify - this problem is only with full-screen applications. In particular on OpenGL. - Mikhail Tsaryov