Link
Skip to main content

Java PNG Writer

The JDeli Java image library includes a PNG Writer to write PNG files in Java. The PNG Encoder is written in 100% Java and provides PNG support 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.

Mode: Throughput Count: 25 Units: ops/s

Benchmark Score Error
Apache 5.100 ± 0.018
ImageIO 4.819 ± 0.010
ImageIO_fast 5.597 ± 0.014
ImageIO_max_comp 3.512 ± 0.008
JDeli 5.383 ± 0.033
JDeli_quantised 1.192 ± 0.001
JDeli_fast 13.061 ± 0.026
JDeli_compressed 5.402 ± 0.027
JDeli_uncompressed 12.985 ± 0.088

Number of files: 166

Benchmark Size unreadable output AVG SSIM score AVG Similarity
Apache 2.61MB 0 0.967281580718986 Very similar (high quality)
ImageIO 2.64MB 0 1.0 Identical or virtually identical
ImageIO_fast 2.74MB 0 1.0 Identical or virtually identical
ImageIO_max_comp 2.62MB 0 1.0 Identical or virtually identical
JDeli 2.62MB 0 1.0 Identical or virtually identical
JDeli_compressed 2.62MB 0 1.0 Identical or virtually identical
JDeli_fast 2.74MB 0 1.0 Identical or virtually identical
JDeli_quantised 0.514MB 0 0.9926136438484626 Identical or virtually identical
JDeli_uncompressed 2.74MB 0 1.0 Identical or virtually identical

Tested on 2020 13inch M1 MacBook Pro using JDK 18.0.1.1


Why JDeli?

  • Support image formats such as AVIF, HEIC and JPEG XL that are not supported in Java.
  • Process images up to 3x faster than ImageIO and alternative Java image libraries.
  • Prevent JVM crashes caused by native code in other image libraries such as ImageIO.
  • Handle JPEG, PNG, TIFF image file formats fully in Java.
  • Keep your Image files secure as JDeli makes no calls to any external system or third party library.

Learn more about JDeli

Start Your Free Trial