Link
Skip to main content

Java JPEG2000 Writer

Java’s built-in ImageIO does not support writing JPEG2000 files. JDeli is a 100% Java JPEG2000 writer that provides full encoding control with no dependencies.

Getting started

Add JDeli to your project via Maven or Gradle, or see using JDeli with Java modules.

What is supported

The JDeli JPEG2000 writer supports the following features:

Feature Supported
Alpha transparency Yes
Colour optimisation Yes
BufferedImage input Yes
Compression - 8bit Quantised Yes
Compression - ZLIB Yes with options for better compression or speed
Metadata EXIF
Output to file Yes
Output to OutputStream Yes
Output to byte[] Yes
Pure Java implementation Yes

Quick start or to replace in existing code using ImageIO:

The simplest way to write a JPEG2000 image is:

JDeli.write(bufferedImage, "jpx", file);

Or to a byte array:

byte[] jpxData = JDeli.write(bufferedImage, "jpx");

Or to an OutputStream:

JDeli.write(bufferedImage, "jpx", os);

Simple usage

For better type safety, use OutputFormat:

JDeli.write(myBufferedImage, OutputFormat.JPEG2000, outputStreamOrFile);

OutputFormat allows setting of any supported Image Format

Benefits:

  • Compile-time safety
  • Cleaner code
  • Recommended for new applications

Advanced usage: controlling the output

Use jpxEncoderOptions when you need control over encoding behaviour.

final Jpeg2000EncoderOptions options = new Jpeg2000EncoderOptions();

//set any options in options instance - examples below
options.setOutputSubtype(Jpeg2000OutputSubtype.JP2); 
// or options.setOutputSubtype(Jpeg2000OutputSubtype.JPX); 
options.setQuality(100);//0-100

//write out
JDeli.write(myBufferedImage, options, outputStreamOrFile);

Jpeg2000EncoderOptions 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 results using JMH:
Mode: Throughput Count: 25 Units: ops/s

Benchmark Score Error
ImageIO/JAI 2.306 ± 0.007
JDeli_JP2 6.226 ± 0.023
JDeli_JPX 6.228 ± 0.020

Number of files: 166

Benchmark Size unreadable output AVG SSIM score AVG Similarity
ImageIO/JAI 1,419.60KB 0 0.9659635878077559 Very similar (high quality)
JDeli JP2 288.66KB 0 0.8817187006016771 Similar (noticeable but minor differences)
JDeli JPX 277.31KB 0 0.8817187006016771 Similar (noticeable but minor differences)

Tested on 2020 13inch M1 MacBook Pro using JDK 18.0.1.1


Frequently asked questions

Can Java write or encode JPEG2000 files without external libraries?

No. Java’s built-in ImageIO does not support writing or encoding JPEG2000 files. JDeli provides a pure-Java JPEG2000 encoder with no dependencies required.

Does writing or encoding JPEG2000 in Java with JDeli require additional libraries?

No. JDeli is a 100% Java library with no dependencies. It runs on any platform where the JVM runs with no additional installation.

What output types does JDeli support for writing JPEG2000?

JDeli can write and encode JPEG2000 to a File, OutputStream, or return the encoded data as a byte array.

See also


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