Java PNG Writer
JDeli includes a PNG Writer to write PNG files in Java. The PNG Encoder is written in 100% Java with no dependencies.
Key information:
- 100% Java solution. No dlls or dependencies on native code
- Relatively faster compression
- PngQuantization: Supports 8-bit Compression which reduces the size of any PNG file by indexing colours
Quick start or to replace in existing code using ImageIO:
JDeli.write(myBufferedImage, "png", outputStreamOrFile);
or
byte[] outputData = JDeli.write(myBufferedImage, "png");
New method for quick and simple usage
JDeli.write(myBufferedImage, OutputFormat.PNG, outputStreamOrFile)
OutputFormat allows setting of any supported Image Format
For complete control of output:
final PngEncoderOptions options = new PngEncoderOptions();
//set any options in options instance - examples below
options.setCompressionFormat(PngCompressionFormat.QUANTISED8BIT);
options.setCompressionFormat(PngCompressionFormat.NONE);
//write out
JDeli.write(myBufferedImage, options, outputStreamOrFile);
PngEncoderOptions 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.
Benchmark | Mode | Cnt | Score | Error | Units |
---|---|---|---|---|---|
PNG.Apache | thrpt | 25 | 0.251 | ± 0.01 | ops/s |
PNG.ImageIO | thrpt | 25 | 0.611 | ± 0.01 | ops/s |
PNG.JDeli_QUANT | thrpt | 25 | 0.347 | ± 0.01 | ops/s |
PNG.JDeli_FAST | thrpt | 25 | 1.694 | ± 0.05 | ops/s |
PNG.JDeli_COMPRESS | thrpt | 25 | 0.649 | ± 0.01 | ops/s |
Tested on 2020 13inch M1 MacBook Pro using JDK 18.0.1.1