ScreenShot 解决方案截取我的桌面的屏幕截图

发布于 2024-12-28 11:21:51 字数 459 浏览 2 评论 0原文

我目前正在制作一款全屏游戏,我希望能够截取一些屏幕截图。 我发现了这个小代码片段:

BufferedImage image = 
new Robot().createScreenCapture(new Rectangle(w.getX(), w.getY(),w.getWidth(),w.getHeight()));

ImageIO.write(image, "jpg", new File("C:\\Users\\Kaizer\\Desktop\\", "ScreenShot"             + counter + ".jpg"));

我知道它看起来不漂亮,但它生成了一个屏幕截图,但来自我的桌面,而不是我实际的全屏游戏。 Windows 屏幕截图的作用相同。

我知道我忽略了一些事情,但我一生都无法弄清楚。

顺便说一句:当玩家按下 F11 按钮时,就会运行此代码。它不是它自己的方法。

I am currently making a fullscreen game and I want to be able to take some screenshots.
I have found this little code snippet:

BufferedImage image = 
new Robot().createScreenCapture(new Rectangle(w.getX(), w.getY(),w.getWidth(),w.getHeight()));

ImageIO.write(image, "jpg", new File("C:\\Users\\Kaizer\\Desktop\\", "ScreenShot"             + counter + ".jpg"));

I know it doesnt look pretty, but it makes a screenshot, but from my desktop, and not my actual fullscreen game. The Windows screenshots does the same.

I know there is something I overlooked, but I can't figure it out for the life of me.

By the way: this code is run when the player presses the F11 button. It is not its own method.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独留℉清风醉 2025-01-04 11:21:51

如果您使用 Swing 或 AWT 编写游戏,而不是使用 Robot,您可以执行以下操作:

private static void captureImage(Component c, String fileName)
        throws IOException {
    BufferedImage img = new BufferedImage(c.getWidth(), c.getHeight(),
            BufferedImage.TYPE_INT_RGB);
    c.paint(img.getGraphics());

    ImageIO.write(img, "jpg", new File(fileName + ".jpg"));
}

注意:根据您使用的 Component,它可能会或可能会不需要可见。但当你在游戏中拍照时,我很确定这并不重要。

If you wrote your game with Swing or AWT, instead of using Robot, you can do the following:

private static void captureImage(Component c, String fileName)
        throws IOException {
    BufferedImage img = new BufferedImage(c.getWidth(), c.getHeight(),
            BufferedImage.TYPE_INT_RGB);
    c.paint(img.getGraphics());

    ImageIO.write(img, "jpg", new File(fileName + ".jpg"));
}

Note: Depending on the Component you're using, it may or may not need to be visible. But seeing as you're taking a picture from a game, I'm pretty sure that won't matter.

ι不睡觉的鱼゛ 2025-01-04 11:21:51

来自我的桌面,而不是我实际的全屏游戏..

这是游戏进行主动渲染时的典型机器人(或标准操作系统屏幕截图软件)。 AFAIU对此无能为力(除了 - 用手机摄像头抓取屏幕截图)。

from my desktop, and not my actual fullscreen game..

This is typical of the Robot (or standard OS screenshot software) when a game does active rendering. AFAIU there is nothing that can be done about it (beyond - grab your screenshots with your phone camera).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文