java - 如何使用java捕获其他应用程序的选定屏幕?

标签 java screenshot

我们正在尝试开发屏幕捕获实用程序。

我们如何使用 Java 捕获另一个应用程序的选定屏幕?我们如何向捕获的屏幕添加标注?

最佳答案

基于 Prajakta's description of the project , 我相信对操纵屏幕截图的一些解释是合适的(我认为约翰在解释 how to capture the screen shot using the java.awt.Robot class 方面做得很好)。请记住,作为 Steve McLeod said , Java 可能无法自动定位要捕获的窗口在屏幕上的位置。这很重要,因为 Robot 类需要知道这个位置,无论是自动还是手动。

调用屏幕截图的 BufferedImage 的 createGraphics() 方法时,您可以通过接收到的 Graphics2D 对象将标注、文本、图像等添加到屏幕截图中.我强烈建议您查看 the Graphics2D's API更好地了解它的功能。我还建议查找一些教程,也许从 the 2D Graphics Tutorial from Sun 开始。 .名为“Filthy Rich Clients”的书也可能有用。

当你最终想保存这个修改后的屏幕截图时,你可以使用 ImageIO 的“写入”方法之一。类。

这是一个非常简单的从头到尾的示例。您可以填写任何必要的详细信息。

希望对您有所帮助!

Robot robot = new Robot();

// The hard part is knowing WHERE to capture the screen shot from
BufferedImage screenShot = robot.createScreenCapture(x, y, width, height);
Graphics2D graphics = screenShot.createGraphics();

// Add a label to the screen shot
Color textColor = Color.RED;
graphics.setColor(textColor);
graphics.drawString("Some text", textX, textY);

// Save your screen shot with its label
ImageIO.save(screenShot, "png", new File("myScreenShot.png"));

关于java - 如何使用java捕获其他应用程序的选定屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/464593/

相关文章:

Java(机器人)屏幕截图超出可见范围

Android读取fb0总是给我黑屏

windows远程桌面不渲染

c# - 只捕获表格一部分的屏幕截图?

java - 正则表达式 - 自定义命令+紧随其后的大写字母

java - 重启android studio时出现多个java.exe

java - 无法在(Android)中点击调试器

java - 如何修复同一 Maven 模块中类的 ClassNotFoundException

java - 解析纬度/经度数组列表以获得最西纬度

screenshot - 为多个网站拍摄多个视口(viewport)屏幕截图