Since we started to support both JPEG and JPEG 2000 as image file outputs in our software, we have found that this is a very common question. So I thought a brief general explanation would be helpful.
JPEG versus JPEG 2000
JPEG files have the file endings .jpg .jpeg .jpe .jif .jfif .jfi while JPEG 2000 files finish with .jp2 .jpx .j2c .j2k .jpf. So kitten.jpg is a JPEG file and kitten.jp2 would be a JPEG 2000 version.
JPEG is the original standard and JPEG 2000 is the newer format. Both are open ISO standards with documentation online. If you want to read up, good starting points are https://jpeg.org/ or https://jpeg.org/jpeg2000/
JPEG 2000 has some interesting new features, but it is not a direct replacement for JPEG – there are still things JPEG does better and not all tools currently support JPEG 2000. The documentation online tends to be very technical and tell you about lots of the features (JPEG 2000 ROI for example) but not the pros and cons.
So I asked our development team to summarise for me in reasonably non-technical language the benefits of each.
JPEG is really good for
- Optimum for small images
- is widely supported
JPEG is not so good for
- Not that great for scanned images containing text
- Low compression ratio for lossy compression
How does JPEG 2000 compare?
- Better on large images (smaller images jpg is still smaller).
- Single decompression architecture
- Lossy and lossless compression
- No universal browser support
- Encoding is CPU intensive and encoding is not as fast and easy as encoding in jpeg.
- file format is less likely to be affected by ‘bit errors’ and other file system errors due to its more efficient coding structure
- Not backward compatible
- File extension:
- handling JPEG 2000 files is much more complex and requires more memory to process.
Which Image format to use?
JPEG where I need to ensure it works on everything, have small images and do not need to get the smallest possible file sizes.
JPEG 2000 where I have fast machines, want the best compression and am confident the users will be able to view them.
How to read and write JPEG and JPEG 2000 images in Java?
We have tutorials on
- How to read JPEG images
- How to write JPEG images
- How to read JPEG2000 images
- How to write JPEG2000 images
Are you a Java Developer working with Image files?
// Read an image
BufferedImage bufferedImage = JDeli.read(dicomImageFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(heicImageFile);
// Write an image
JDeli.write(bufferedImage, "heic", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(jpegImageFile);
// Write an image
JDeli.write(bufferedImage, "jpeg", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(jpeg2000ImageFile);
// Write an image
JDeli.write(bufferedImage, "jpx", outputStreamOrFile);
// Write an image
JDeli.write(bufferedImage, "pdf", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(pngImageFile);
// Write an image
JDeli.write(bufferedImage, "png", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(tiffImageFile);
// Write an image
JDeli.write(bufferedImage, "tiff", outputStreamOrFile);
// Read an image
BufferedImage bufferedImage = JDeli.read(webpImageFile);
// Write an image
JDeli.write(bufferedImage, "webp", outputStreamOrFile);
Why do developers choose JDeli over free alternatives?
- Works with newer image formats such as AVIF, HEIC, JPEG XL, WEBP
- Better support than alternatives for JPEG, PNG, TIFF.
- Prevent JVM crashes caused by native code in other image libraries
- Better performance than other popular Java image libraries