如何使用java捕获其他应用程序的选定屏幕? [英] How to capture selected screen of other application using java?

查看:112
本文介绍了如何使用java捕获其他应用程序的选定屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

We are trying to develop a screen capture utility.

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

How do we capture selected screen of another application using Java? And how do we add a callout to the captured screen?

推荐答案

基于 Prajakta对项目的描述,我相信操纵屏幕截图的一些解释是有序的(我认为John做了很好的解释如何使用java.awt.Robot类捕获屏幕截图)。请记住,正如 Steve McLeod所说,Java可能无法自动定位您要在屏幕上捕获的窗口的位置。这很重要,因为Robot类需要自动或手动知道这个位置。

Based on Prajakta's description of the project, I believe some explanation of manipulating a screen shot is in order (I think John did an excellent job of explaining how to capture the screen shot using the java.awt.Robot class). Remember, as Steve McLeod said, Java may not be able to automatically locate the location of the window you want to capture on the screen. This is important, because the Robot class needs to know this location, either automatically or manually from you.

可以在屏幕截图中添加标注,文本,图像等通过您在调用屏幕截图的 BufferedImage 。我强烈建议您查看 Graphics2D的API 更好地了解它的能力。我还建议找一些教程,可能从 2D图形教程开始孙。标题为肮脏的富客户端的书也可能有用。

Callouts, text, images, etc can be added to the screen shot via the Graphics2D object you receive when you call the createGraphics() method of the screen shot's BufferedImage. I highly recommend you check out the Graphics2D's API to better understand what it is capable of. I also recommend finding some tutorials, perhaps starting with the the 2D Graphics Tutorial from Sun. The book entitled "Filthy Rich Clients" may also come in useful.

当你最终要保存这个修改过的屏幕截图时,可以使用 ImageIO 类。

When you finally want to save this modified screen shot, you can use the one of the "write" methods of the ImageIO class.

这是一个非常简单的,从头到尾的例子。您需要填写必要的详细信息。

Here is a very simple, start-to-finish example. It is up to you to fill in whatever details necessary.

我希望这有点帮助!

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捕获其他应用程序的选定屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆