11 Dec 2017

Write program in java to capture windows screen.


this program will capture your windows screen and save into directory as mentioned in it. further you can change this according to your need.

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import java.util.Random;
class shot
{
          public static void main(String[] args) throws AWTException,IOException
          {
                   Robot r=new Robot();
                   String format="jpg";

                   String filename=System.currentTimeMillis()+"myshot."+format;
                   Rectangle rec=new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
                   BufferedImage screenImage=r.createScreenCapture(rec);
                   ImageIO.write(screenImage,format,new File("F:/CapturedImage/" +filename));
                   System.out.println("done");
          }
}


Output:

when you will run this program, this will capture your current screen and save into " F:/CapturedImage/ " this location.