ImageIO.write慢吗? [英] ImageIO.write slow?
本文介绍了ImageIO.write慢吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个应用程序,其中我每秒写入大约25个png图像文件到磁盘.
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);
每个呼叫通常需要150毫秒,因此无法达到25fps.我可以缓冲IO以便不丢失任何帧吗?
It usually takes 150ms per call, and achieving 25fps hence becomes impossible. Can I buffer IO so that I don't drop any frames?
推荐答案
PNG编码需要一段时间,并且您无法通过任何缓冲对其进行改进...如果要提高速度,请使用BMP(这会消耗您的BMP)HDD),或者如果不需要像素质量,请尝试JPG(应比PNG更快地进行编码).
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).
这篇关于ImageIO.write慢吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文