The following code captures the screen:
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
public class capture{
    public static void main(String args[]) { 
        try { 
            Dimension size = Toolkit.getDefaultToolkit().getScreenSize(); 
            Robot robot = new Robot(); 
            BufferedImage img = robot.createScreenCapture(new Rectangle(size)); 
        } catch(Exception e) { 
        } 
    }
}
Is there a way, to capture only a desired portion of the screen (e.g. a rectangle, from one x,y point to another)?
You can set the x and y of the top left corner, along with the width, and height dimensions of the rectangle to capture like this:
BufferedImage img = robot.createScreenCapture( new Rectangle(x, y, width, height) );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With