1

I am trying to use Robot in Java to make an image file of a print screen. So far I have:

 Robot robot = new Robot();
 Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
 BufferedImage capture = new Robot().createScreenCapture(screenRect);
 ImageIO.write(capture, "bmp", new File("printscreen.bmp"));

But I can't seem to get it to create the file.

Jason Plank
  • 2,342
  • 4
  • 32
  • 40
Harry Martland
  • 595
  • 2
  • 13
  • 23

2 Answers2

5
s/printscreen.bmp/"printscreen.bmp"
OscarRyz
  • 190,799
  • 110
  • 376
  • 555
0

Not sure if .bmp files are support. Oops, they are:

System.out.println( Arrays.asList( ImageIO.getWriterFileSuffixes() ) );

You can also use the Screen Image class for some more general screen printing features.

camickr
  • 316,400
  • 19
  • 155
  • 279