Skip to content
Advertisement

Increase resolution of java screenshot

I am using the following code to take a screenshot in Java:

import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;

import javax.imageio.ImageIO;

import java.io.File;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws AWTException, IOException{
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Rectangle screenRectangle = new Rectangle(screenSize);
        Robot robot = new Robot();
        BufferedImage image = robot.createScreenCapture(screenRectangle);
        ImageIO.write(image, "png", new File("Path/To/screenshot.png"));
    }
}

This code works, but the screen shot outputted is fairly low resolution. How can I increase the resolution of the screenshot?

Advertisement

Answer

There is nothing wrong with this code. I have a screen resolution of 1680×1050 pixels, and the generated png file has exactly this size.

Advertisement