Mark Stephens Mark founded the company and has worked with Java and PDF since 1997. The original creator of the core code, he is also a NetBeans enthusiast who enjoys speaking at conferences and reading. He holds an Athletics Blue and an MA in Mediaeval History from St. Andrews University.

How to write JPEG 2000 Images in Java

3 min read

JPEG2000 icon

how to write JPEG2000 image (JPEG2000 icon)

TL;DR:

Java’s ImageIO has partial JPEG2000 support — it handles the jp2 subformat but not jpx. For complete, reliable JPEG2000 output without native dependencies, you need an external library. JDeli is a pure Java option that works as a drop-in ImageIO plugin and provides a direct API. A free alternative using native binaries is available via the jai-imageio-jpeg2000 library on GitHub.

Does Java support JPEG2000 natively?

Partially. ImageIO includes basic JPEG2000 support for the jp2 subformat, but jpx is not supported. Attempting to write jpx will fail silently:

// jp2 — may work with native ImageIO depending on Java version
File file = new File("/path/to/output.jp2");
boolean result = ImageIO.write(bufferedImage, "jpeg2000", file);
// jpx — returns false, no writer available
File file = new File("/path/to/output.jpx");
boolean result = ImageIO.write(bufferedImage, "jpeg2000", file);
// result = false

As with ImageIO.write() in general, always check the return value — it returns false rather than throwing when no suitable writer is found.

Which Java JPEG2000 library should you use?

ImageIO (native)jai-imageio-jpeg2000JDeli
Pure Java (no native binaries)✗ (wraps OpenJPEG)
Works as ImageIO plugin
Direct API
jp2 support
jpx support
Encoder optionsLimited
Supports other formats (AVIF, HEIC, PNG, TIFF, WebP…)
CostFreeFreeCommercial
SupportCommunityGitHub issuesIncluded
Actively developedLimited

jai-imageio-jpeg2000 is a reasonable free option if native binaries are acceptable in your environment and you only need ImageIO plugin behaviour. JDeli is the better choice for production use, pure Java environments, or where you need jpx support and encoder control.

Option 1: Write JPEG2000 with native ImageIO

For jp2 output, native ImageIO may be sufficient:

File file = new File("/path/to/output.jp2");
boolean written = ImageIO.write(bufferedImage, "jpeg2000", file);
if (!written) {
    // No suitable ImageIO writer found
    throw new IOException("Failed to write JPEG2000: no suitable writer found");
}

If you need jpx support, a third-party library is required.

Option 2: Add full JPEG2000 support to ImageIO (no code changes)

JDeli registers itself as an ImageIO plugin. Once it is on the classpath, your existing ImageIO.write() calls handle both jp2 and jpx automatically with no code changes required.

Maven

<dependency>
    <groupId>com.idrsolutions</groupId>
    <artifactId>jdeli</artifactId>
    <version>[JDELI_VERSION]</version>
</dependency>

Gradle

implementation 'com.idrsolutions:jdeli:[JDELI_VERSION]'

Alternatively, download the trial jar and add it to your classpath manually. See the ImageIO configuration guide for setup details.

// Your existing ImageIO code — no changes needed
File file = new File("/path/to/output.jp2");
ImageIO.write(bufferedImage, "jpeg2000", file);

Option 3: Write JPEG2000 directly with the JDeli API

The JDeli API gives you more control and does not depend on ImageIO’s plugin registration order.

  1. Add JDeli to your class or module path. (download the trial jar)
  2. Create a File or OutputStream for the output.
  3. Call JDeli.write() with your image, format, and output target.
// String format
JDeli.write(bufferedImage, "jp2", new File("/path/to/output.jp2"));
// Type-safe enum (preferred)
JDeli.write(bufferedImage, OutputFormat.JPEG2000, new File("/path/to/output.jp2"));

Controlling output with Jpeg2000EncoderOptions

For production use, pass a Jpeg2000EncoderOptions object to control compression and other output settings:

Jpeg2000EncoderOptions options = new Jpeg2000EncoderOptions();
JDeli.write(bufferedImage, options, new File("/path/to/output.jp2"));

See the JDeli JPEG2000 documentation for the full list of encoder options.

Frequently asked questions

What is JPEG2000?

JPEG2000 is an image compression standard published in 2000 as a successor to JPEG. It supports both lossless and lossy compression, delivers better quality than JPEG at equivalent file sizes, and is used in medical imaging (DICOM), digital cinema (DCP), and archival workflows. The two main subformats are jp2 (the base format) and jpx (an extended profile).

What is the difference between jp2 and jpx?

jp2 is the base JPEG2000 file format. jpx is an extended profile that supports additional features including ICC colour profiles, transparency layers, and more complex metadata. Java’s native ImageIO handles jp2 only; jpx requires a third-party library such as JDeli.

Can I read JPEG2000 files in Java with JDeli?

Yes. See our companion article: how to read JPEG2000 files in Java.

Is JDeli pure Java?

Yes. JDeli has no native binaries and makes no calls to platform-specific libraries, making it straightforward to deploy on any Java-supported platform including containerised and server environments.

What is JDeli?

JDeli is a pure Java image library from IDR Solutions. It supports reading, writing, and converting JPEG2000 and other formats including AVIF, HEIC, PNG, TIFF, and WebP. It works as both an ImageIO plugin and a standalone API.

Other useful JPEG2000 resources

As experienced Java developers, we help you work with images in Java and bring over a decade of hands-on experience with many image file formats.



Are you a Java Developer working with Image files?

Mark Stephens Mark founded the company and has worked with Java and PDF since 1997. The original creator of the core code, he is also a NetBeans enthusiast who enjoys speaking at conferences and reading. He holds an Athletics Blue and an MA in Mediaeval History from St. Andrews University.