ImageIO.write slow?

人走茶凉 提交于 2021-02-07 07:01:25

问题


I've an application where I'm writing around 25 png image files to disk every second.

BufferedImage img = getBufferedImage();
// code below is very slow ~150ms.
File file = new File(count++ + ".png");
BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(file));
ImageIO.write(img, "png", os);

It usually takes 150ms per call, and achieving 25fps hence becomes impossible. Can I buffer IO so that I don't drop any frames?


回答1:


PNG encoding takes a while and you can't improve it with any buffering ... if you want a speed up, use BMP (which will eat up your HDD) or if pixel-quality is not needed, try JPG (which should get encoded faster than PNG).



来源:https://stackoverflow.com/questions/9973071/imageio-write-slow

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!