我正在 Java 中创建一个应用程序,使用以下代码按时间间隔捕获屏幕截图:
Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage capture = new Robot().createScreenCapture(screenRect);
ImageIO.write(capture, "bmp",new File("img/screenshot.png"));
我得到了输出,但问题是图像的大小接近 3MB。如何在捕获图像时减小图像的大小?
最佳答案
将 bmp 更改为 png 或 jpg
ImageIO.write(capture, "png",new File("img/screenshot.png"));
来自 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.
关于java - 如何减小java中截图图像的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23010237/