0

I am creating an application in Java to capture a screenshot at a time interval using the following code:

Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage capture = new Robot().createScreenCapture(screenRect);
ImageIO.write(capture, "bmp",new File("img/screenshot.png"));

I got the output but the problem is that the size of image is near 3MB. How I can decrease the size of the image at time of capturing it?

eltabo
  • 3,749
  • 1
  • 21
  • 33
Uday A. Navapara
  • 1,237
  • 5
  • 20
  • 40

1 Answers1

1

change bmp to png or jpg

ImageIO.write(capture, "png",new File("img/screenshot.png"));

from the docs at http://docs.oracle.com/javase/tutorial/2d/images/saveimage.html

The ImageIO.write method calls the code that implements PNG writing a “PNG writer plug-in”. >The term plug-in is used since Image I/O is extensible and can support a wide range of formats.

But the following standard image format plugins : JPEG, PNG, GIF, BMP and WBMP are always be present.

Moh-Aw
  • 2,976
  • 2
  • 30
  • 44
  • It is especially misleading if you create a file called `screenshot.png` but the content of that file is in `bmp` format. BMP is a completely uncompressed and therefore creates large files. – SebastianH Apr 11 '14 at 13:32