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?
Are you a Developer working with PDF files?
|Free: The Developer's Guide to PDF|
|Convert PDF files to HTML|
|Use PDF Forms in a web browser|
|Convert PDF Documents to an image|
|Work with PDF Documents in Java|