简体   繁体   English

如何从directX获取java的屏幕截图

[英]How to take a screenshot with java from directX

I'm looking for a way to take a screenshot with a Java application of any running directX game. 我正在寻找一种方法来获取任何正在运行的directX游戏的Java应用程序的屏幕截图。 I use 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 one works perfectly anywhere but in directX games. 这款游戏适用于任何地方,但在DirectX游戏中。 I'm not that familiar with Java and even less with DirectX, I'm just trying to adjust this code. 我不熟悉Java,甚至不太熟悉DirectX,我只是想调整这段代码。 I googled very much, but everything just leads to the same code I already have. 我google了很多,但一切都只是导致了我已经拥有的相同代码。

Do you know of another way to take a screenshot of DirectX games? 你知道另一种截取DirectX游戏截图的方法吗?

Thanks. 谢谢。

Calling GraphicsDevice#getFullScreenWindow might work, though I haven't really tested this code. 调用GraphicsDevice#getFullScreenWindow可能会有效,但我还没有真正测试过这段代码。

    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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM