Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why ImageIO.read() SOOO slow?

So I'm trying to get a PNG image from stream.

image = ImageIO.read(inputStream);

And this code is running for ten seconds! I thought the problem was in slow InputStream, so I tried to load it in buffer first.

byte[] bytes = inputStreamToBytes(inputStream);
image = ImageIO.read(new ByteArrayInputStream(bytes));

And guess what! It takes about 100ms to load it from InputStream to buffer, but hell of a lot of time just to read it from byte array! A ten (TEN) seconds to read! From a RAM!

I'm doing it on Raspberry PI. And yes, I understand it's a toy, not a real computer. So I tried to do it on my MacBook Air. Really, two seconds are better then ten. But still a lot for some 800x600 PNG. So why it so? And what to do?

like image 665
user1748526 Avatar asked Nov 17 '25 16:11

user1748526


1 Answers

You probably need to install Java Native IO libraries they are not installed by default.

http://www.oracle.com/technetwork/java/install-jai-imageio-1-0-01-139659.html

If you don't have this lib installed all operations on images are performed in java not natively.

like image 162
Greg Avatar answered Nov 19 '25 06:11

Greg