In this article, I will talk you through on how to read JPEG2000 images into a BufferedImage using ImageIO/JAI and our JDeli Image Library. So let us start from the basics, what is JPEG2000?
What is JPEG2000?
JPEG2000 is an image decoding standard that was originally created as an update of the well known JPEG Format which was introduced in the year 2000 by the
“Joint Photographic Experts Group” committee. It uses lossy compression image mode that is based on discrete wavelet transformation.
JPEG2000 compared to JPEG offers:
- A better higher compression performance,
- Outputs of multiple resolutions,
- The option for both lossless and lossy compression,
- Improved noise resilience,
- Flexibility in file formats,
- Bit depth support,
- advance support for transparency and alpha planes.
The filename extensions commonly associated with JPEG 2000 are:
Example Java code to read a JPEG2000 image in Java:
Here is some sample code using ImageIO/JAI and JDeli. (ImageIO needs JAI installed to support JPEG2000).
//Read Image from File File myJPegFile = new File("ImageAsJPeg.jp2"); BufferedImage image = ImageIO.read(myJPegFile);
You can easily replace ImageIO (and get much better support for JPEG2000 files) by just changing ImageIO.read to JDeli.read:
//Read Image (can also be OutputStream or byte array) File myJpegFileFile = new File("ImageAsJPeg.jp2"); BufferedImage image = JDeli.read(myJPegFile);
Or you can use the JDeli Jpeg2000Decoder directly:
Jpeg2000Decoder decoder = new Jpeg2000Decoder(); BufferedImage decodedImage = decoder.read(imageByteData);
Features Included in JDeli JPEG2000 Decoder:
- Colorspace : Bitlevel, Grayscale, RGB, CMYK and YCCK images
- Bits Per Sample : 1 to 16
- In additionally JDeli offers fastest JPEG2000 Decoding capability in java
Why use JDeli?
JDeli offers a range of advantages over ImageIO and alternatives, including:
- prevents heap related JVM crashes
- implements unsupported image formats
- reduce output file size
- improve read/write performance
- supports threading
- superior image scaling algorithms
This article is part of our series on reading and writing image files in Java.
IDRsolutions develop a Java PDF library, a PDF forms to HTML5 converter, a PDF to HTML5 or SVG converter and a Java Image Library that doubles as an ImageIO replacement. On the blog our team post about anything interesting they learn about.