简体   繁体   English

拍摄Java中Windows(.exe)上特定应用程序的屏幕截图

[英]Take a screenshot of a specific application on Windows (.exe) in java

Is it possible to take a screen capture of a specific application/exe launched on Windows in Java ? 是否可以对在Windows中以Java启动的特定应用程序/ exe进行截屏?

I tried this code but it does not take a capture of the application itself and return a black picture: 我尝试了这段代码,但没有捕获应用程序本身并返回黑色图片:

try {
    ...
    Robot robot = new Robot();
Rectangle captureSize = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
    BufferedImage bufferedImage = robot.createScreenCapture(captureSize);
    ImageIO.write(bufferedImage,"png",myFile);  
    ...
}    catch(AWTException e) {
    System.err.println("call a doc!");
}

This is why I think that forcing a screenshot linked with the process launched may solve the problem. 这就是为什么我认为强制与启动的过程链接的屏幕快照可以解决问题的原因。

Or maybe they are other ways to take a capture of the displayed screen? 还是它们是捕获显示屏幕的其他方法? (if yes could you please show me some working code?) (如果可以,请告诉我一些工作代码?)

Check this code . 检查此代码。

public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub
        Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
        BufferedImage capture = new Robot().createScreenCapture(screenRect);
        ImageIO.write(capture, "bmp", new File("D:/Newimage.bmp"));     
    }

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

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