How to take screenshot using java from directX

I'm looking for a way to take a screenshot with a Java application of any DirectX game running. I am using the following code

Robot robot = new Robot();  
GraphicsConfiguration config = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();  
BufferedImage screenshot = robot.createScreenCapture(config.getBounds());  
ImageIO.write(screenshot,"png", file); 

      

This works fine, but in DirectX games. I'm not familiar with Java and even less with DirectX, I'm just trying to tweak this code. I've googled a lot, but everything just leads to the same code that I already have.

Do you know of another way to take a screenshot of DirectX games?

Thank.

+3


source to share


1 answer


The call GraphicsDevice#getFullScreenWindow

might work, although I haven't really tested this code.



    BufferedImage screenshot;
    GraphicsDevice gd = GraphicsEnvironment
            .getLocalGraphicsEnvironment()
            .getDefaultScreenDevice();
    Window window = gd.getFullScreenWindow();
    if(window == null) {
        Robot robot = new Robot();
        GraphicsConfiguration config = gd.getDefaultConfiguration();
        screenshot = robot.createScreenCapture(config.getBounds()); 
    } else {
        screenshot = new BufferedImage(window.getWidth(),
                window.getHeight(),
                BufferedImage.TYPE_INT_RGB);
        window.paint(screenshot.getGraphics());
    }
    ImageIO.write(screenshot, "png", file);

      

0


source







All Articles