Based on the Stack Overflow post that was given in a comment, you can do this with fairly easily it appears.

In that post it looks like you can use .awt.Robot to create an image with pixels that are taken from the screen…a screenshot. The code that they give is:

Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage capture = new Robot().createScreenCapture(screenRect);
ImageIO.write(capture, "jpg", new File(args[0]));

Keep in mind that this is nearly 10 year old code and will only capture the primary monitor.

The ImageIO.Write() method takes a parameter that allows for different image formats:

ImageIO.write(capture, "jpg", new File(args[0]));

This ImageIO takes the buffered image from the robot and writes it to a file of any format that you like.

Just change the "jpg" to the format you want and give it a test to make sure that it works.



Source link https://sqa.stackexchange.com/questions/35066/taking--using-the-java--

LEAVE A REPLY

Please enter your comment!
Please enter your name here