We have been doing a lot of work recently on images in Java and will be writing a series of articles on JPEG2000 support, access, bugs and other issues. First off, I want to take a look at performance.
When you are generating a PDF image a lot of time is spent in ImageIO, either decoding the DCTDecode image (which is a JPEG) and writing out the final image as a PNG. Here is what I have found out for trying to speed this up.
1. Doing the conversion in memory does not speed things up.
2. Using a BufferedOutputStream for ImageIO.write images seems to have a marginal improvement on some systems.
3. The ImageIO.write is optimised for Indexed Colorspaces so it is often quicker to convert the image to an Index Colorspace and then write it out. Here is some sample code.
BufferedImage indexedImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_INDEXED); Graphics2D g = indexedImage.createGraphics(); g.drawImage(image, 0,0,null); image=indexedImage;
4. JAI JPEG decoding seems to be much slower than ImageIO (certainly on my Mac).
5. ImageIO.setUseCache(true) is slower
Comparing the performance we get in Java compared to non-Java solutions also seems to be disappointing at the moment. So I hope it will be something Sun looks at for Java 8.
Do you have any tips for improving Java ImageIO performance?
Latest posts by Mark Stephens (see all)
- How we are improving our code quality with IDEA in 2018 - March 7, 2018
- How we are improving our code quality with NetBeans in 2018 - March 1, 2018
- 3 ways that the European Union is changing the way Companies write software in 2018 - January 31, 2018
- IDRsolutions product range update for 2018 - January 22, 2018
- 4 ways Companies can make remote working successful - December 21, 2017