Bethan Palmer Bethan is a Java developer and a Java Champion. She has spoken at conferences including JavaOne/Code One, DevFest and NetBeans days. She has a degree in English Literature.

Are you a Java Developer working with Image files?

Read and write images in Java with JDeli

Speed Comparisons of Java Image Libraries: ImageIO, JAI & JDeli

2 min read

Image Comparison

Here at IDRSolutions we have been working on our Java PDF Library and JPDF2HTML5 solutions since 1999 and more recently with Images.

How did this happen? Well you have ever needed to read or write any images in Java, you have probably come across the Java Advanced Imaging (JAI) API and the ImageIO class. Here at IDRsolutions we originally used ImageIO and JAI when working with image file formats. But we noticed that we were getting less than satisfactory results.

What is JDeli?

Back in 2015, we decided to move away from using ImageIO and JAI, and released our own image library: JDeli. JDeli has a high level of support for images and wide range of image support. JDeli is a library created by IDRSolutions which fixes some to most of the bugs which can be found in ImageIO and JAI and adds support for other image formats.

How did we make the comparisons on the speed?

We were curious to see how JDeli performed against ImageIO and JAI. Therefore we decided to run some tests to compare how long it took to read and write several different file types.

How did we make it a fair test?

Every test was carried out on the same Windows machine, using the same sample of image files where the file type was supported. The times given are the time it took to read or write all of the relevant image files in the directories.

To ensure a fair test we discounted the following image formats: WebP, Dicom, PSD, SGI. These formats can be read with JDeli but are not supported by ImageIO or JAI and therefore have not been included in these tests.

How did we run these tests?

To begin with we tested ImageIO against JDeli using our first directory which contained the following file types:

File typesReadingWriting
JPEGYesYes
PNGYesYes
BMPYesYes

Once those tests were completed we knew we would have to create a second directory with different files because ImageIO is not capable of decoding file types such as TIFF and JPEG2000.

Our second file directory contained the following file types:

File typesReadingWriting
TIFFYesYes
JPEG2000YesNo

ImageIO / JAI vs JDeli

Before running the tests, I was unsure which would be faster. JDeli was created as a superior alternative to ImageIO and JAI, but this was the first time I had made a full set of tests to find a definitive answer. I would however expect JDeli to be slower when writing JPeg files, as it uses native calls.

Speed is an important factor to consider when choosing an image library, especially if you are decoding or encoding a large number of files. However other important considerations include what file types are available. For example JDeli does not currently have support for writing JPeg2000 files, but ImageIO and JAI do not support reading WebP, Dicom, PSD, or SGI. Other factors to consider are pricing and the support available. What you see as the “best” image library depends on your criteria.

The Results

The results from our test are given in seconds and are the time it took for all of the 50 image files in the directories to be read or written.

All of the file formats were tested with ImageIO, but TIFF and JPEG2000 files also require JAI and therefore the results are in a separate column.

File typesNumber of fileImageIOImageIO/JAIJDeli
Reading PNG500.444N/A0.253
Writing PNG500.731N/A0.627
Reading JPEG500.698N/A0.886
Writing JPEG501.537N/A2.848
Reading BMP500.297N/A0.228
Reading TIFF50N/A0.4600.274
Writing TIFF50N/A0.4970.250
Reading JPEG200050N/A55.23528.245

Conclusion

These results show that our software, JDeli, performed the best with PNGs, BMPs, TIFFs and JPeg2000s. However with JPegs, ImageIO was faster. This could be due to the fact that ImageIO uses native calls. However as an overall result JDeli proved to be the quickest in comparison to to ImageIO and JAI. It also manages to fix some bugs. For example, when reading Tiff files I found that lots of the more complex files threw Illegal Argument Exceptions when I tried to read them using ImageIO and JAI. In the interests of fairness I removed them from the tests and replaced them with images which both libraries were able to read.

These results confirm that, in terms of speed, JDeli is overall a better image library. As I mentioned above, “better” is not necessarily just about speed. JDeli also fixes some of the problems with ImageIO, examples of which can be found in our previous blog article on what JDeli offers.

Feel free to try out the tests for yourself as there is a trial download of the JDeli image library you can use.



Find out how to read and write images files in Java with JDeli:

Read: BufferedImage image = JDeli.read(streamOrFile);

Write: JDeli.write(myBufferedImage, OutputFormat.HEIC, outputStreamOrFile)

Learn more >>

Bethan Palmer Bethan is a Java developer and a Java Champion. She has spoken at conferences including JavaOne/Code One, DevFest and NetBeans days. She has a degree in English Literature.