Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

Are you a Java Developer working with Image files?

Read and write images in Java with JDeli

How to write JPEG2000 Images in Java

51 sec read

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);


Find out how to read and write images files in Java with JDeli:

Read: BufferedImage image = JDeli.read(streamOrFile);

Write: JDeli.write(myBufferedImage, OutputFormat.HEIC, outputStreamOrFile)

Learn more >>

Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

What is JBIG2?

JBIG2 is a lossless and lossy compression standard for bi-level images like scanned documents, offering high compression ratios by identifying and encoding similar shapes...
chika
47 sec read