Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageIO.write slow?

Tags:

java

io

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?

like image 596
Taranfx Avatar asked Apr 02 '12 08:04

Taranfx


1 Answers

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).

like image 147
Neet Avatar answered Nov 16 '22 18:11

Neet