I am writing an web application where I need to send an image from servlet to client. Image is generated dynamically and is quite big(+-2MB). It might be jpeg, png, or gif.
Now, I am using ImageIO.write() to write the image to output stream, but its veeeery slow. It takes up to 6 seconds till the client see the image. I need to speed it up.
Any suggestions?
btw. I am aware of Looking for a faster alternative to ImageIO topic. But it didn't help me.
Since it's slow with PNG ImageMagick is not a solution and
I have tested JAI and it was even worse.
Thanks in advance
Edit:
To show you some code:
BufferedImage bi = [code to generate Image];
response.setContentType(mime);
ServletOutputStream out = response.getOutputStream();
ImageIO.write(bi,"png",out);
I stripped down Exception handling for readability.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…