ScreenShot 解决方案截取我的桌面的屏幕截图
我目前正在制作一款全屏游戏,我希望能够截取一些屏幕截图。 我发现了这个小代码片段:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用 Swing 或 AWT 编写游戏,而不是使用
Robot
,您可以执行以下操作:注意:根据您使用的
Component
,它可能会或可能会不需要可见。但当你在游戏中拍照时,我很确定这并不重要。If you wrote your game with Swing or AWT, instead of using
Robot
, you can do the following: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.这是游戏进行主动渲染时的典型机器人(或标准操作系统屏幕截图软件)。 AFAIU对此无能为力(除了 - 用手机摄像头抓取屏幕截图)。
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).