[英]ScreenShot solution takes a screentshot of my desktop
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.
Windows屏幕截图也是如此。
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. 顺便说一句:当玩家按下F11按钮时,将运行此代码。 It is not its own method.
这不是它自己的方法。
If you wrote your game with Swing or AWT, instead of using Robot
, you can do the following: 如果您使用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"));
}
Note: Depending on the Component
you're using, it may or may not need to be visible. 注意:根据所使用的
Component
,它可能不可见。 But seeing as you're taking a picture from a game, I'm pretty sure that won't matter. 但是,看到您正在从游戏中拍照时,我敢肯定这不会有问题。
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. 当游戏进行主动渲染时,这是
Robot
(或标准OS屏幕截图软件)的代表。 AFAIU there is nothing that can be done about it (beyond - grab your screenshots with your phone camera). AFAIU对此无能为力(除此之外-用手机摄像头抓取屏幕截图)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.