简体   繁体   中英

how to decrease the size of screenshot image in java

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM