Java JPEG Writer
The JDeli Java image library includes a JPEG Writer to write JPEG files in Java. The JPEG Encoder is written in 100% Java and provides JPEG support with no dependencies.
Key information:
- 100% Java solution. No dlls or dependencies on native code
- Fast and easy to use
- Supports quality settings
Quick start or to replace in existing code using ImageIO:
JDeli.write(myBufferedImage, "jpg", outputStreamOrFile);
or
byte[] outputData = JDeli.write(myBufferedImage, "jpg");
New method for quick and simple usage
JDeli.write(myBufferedImage, OutputFormat.JPEG, outputStreamOrFile)
OutputFormat allows setting of any supported Image Format
For complete control of output:
final JpegEncoderOptions options = new JpegEncoderOptions();
//set any options in options instance - examples below
options.setQuality(100);//0-100
//write out
JDeli.write(myBufferedImage, options, outputStreamOrFile);
JpegEncoderOptions allows setting of specific options.
Various image processing operations can be conducted on the image, detailed documentation can be found here.
Performance comparisons:
These figures were generated using jmh (as documented on our blog) with a standard set of images (also documented). They should be easy to replicate if you wish to validate, the code is on GitHub.
The higher the number, the better.
Mode: Throughput Count: 25 Units: ops/s
| Benchmark | Score | Error |
|---|---|---|
| ImageIO | 13.345 | ± 0.049 |
| ImageIO_high | 10.049 | ± 0.033 |
| ImageIO_low | 13.989 | ± 0.040 |
| JDeli | 28.073 | ± 0.513 |
| JDeli_high | 15.778 | ± 0.126 |
| JDeli_low | 29.451 | ± 0.491 |
Number of files: 166
| Benchmark | Size | unreadable output | AVG SSIM score | AVG Similarity |
|---|---|---|---|---|
| ImageIO | 201.10KB | 36 | 0.9843408924688256 | Very similar (high quality) |
| ImageIO_high | 922.64KB | 36 | 0.9955252550315202 | Identical or virtually identical |
| ImageIO_low | 110.37KB | 36 | 0.753963280422963 | Moderately similar (visible differences) |
| JDeli | 232.06KB | 0 | 0.9635278566129812 | Very similar (high quality) |
| JDeli_high | 1,484.97KB | 0 | 0.9824853317459952 | Very similar (high quality) |
| JDeli_low | 132.199KB | 0 | 0.7308454760175299 | Moderately similar (visible differences) |
Tested on 2020 13inch M1 MacBook Pro using JDK 18.0.1.1