Site iconJava PDF Blog

How to write JPEG2000 Images in Java

JPEG2000 icon

In this article I will show you how to write JPEG2000 images in Java. We also have a related article covering how to read JPEG2000 files in Java.

ImageIO is able to write images as JPEG2000 files (jp2 format only), but it offers very little control over the process or the output. We added JPEG2000 support to our JDeli Image library so we could get quality JPEG2000 output. In this article, we show you how to use either JDeli or ImageIO and cover the benefits of JDeli.

How to write an image as a JPEG2000 file in ImageIO

  1. ImageIO will need the JAI_ImageIO plugin installed.
  2. Create a File (or OutputStream) object for the JPEG2000 output.
    File file = new File("/path/to/outputFile.jp2"));
  3. Pass image, jpg type and File (or OutputStream) object into write method
    ImageIO.write(bufferedImage, "jpeg 2000", file);

How to write an image as a JPEG2000 file with JDeli

  1. Add JDeli to your class or module path. (download link to the trial jar).
  2. Create a File (or OutputStream) object
    File file = new File("/path/to/outputFile.jp2"));
  3. Pass image, JPEG2000 type and File (or OutputStream) object into write method
    JDeli.write(bufferedImage, "jp2", file);

In JDeli you can also use a typesafe version

JDeli.write(bufferedImage, OutputFormat.JPEG2000, file);

or pass in a Jpeg2000EncoderOptions object for more control over JPEG2000 image output such as level of Compression.

Jpeg2000EncoderOptions options = new Jpeg2000EncoderOptions();
JDeli.write(bufferedImage, options, file);