Simple as the title states: Can you use only Java commands to take a screenshot and save it? Or, do I need to use an OS specific program to take the screenshot and then grab it off the clipboard?
相关问题
- Views base64 encoded blob in HTML with PHP
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- How to get the background from multiple images by
You can use
java.awt.Robot
to achieve this task.below is the code of server, which saves the captured screenshot as image in your Directory.
And this is Client code which is running on thread and after some minutes it is capturing the screenshot of user screen.
bufferedImage will contain a full screenshot, this was tested with three monitors
Toolkit returns pixels based on PPI, as a result, a screenshot is not created for the entire screen when using PPI> 100% in Windows. I propose to do this:
I never liked using Robot, so I made my own simple method for making screenshots of JFrame objects:
Believe it or not, you can actually use
java.awt.Robot
to "create an image containing pixels read from the screen." You can then write that image to a file on disk.I just tried it, and the whole thing ends up like:
NOTE: This will only capture the primary monitor. See GraphicsConfiguration for multi-monitor support.