Java does not support HEIC by default. If you try this code to read or write HEIC image, it will fail.
// Current problem many developers face
//read
try {
ImageIO.read(imageFile);
} catch (IOException e) {
// This fails – ImageIO doesn’t support HEIC
}
//write
try {
ImageIO.write(bufferedImage, "heic", new File("output.heic"));
} catch (IOException e) {
// This fails – ImageIO doesn’t support HEIC
}
This blog post explains how to fix this code using JDeli which supports HEIC files. This can be done by simply using our ImageIO Plugin with no changes to existing code or writing new code using JDeli directly.
What is HEIC?
HEIC stands for “High-Efficiency Image Container” and it is a specific implementation for still images inside HEIF. It was developed by MPEG and adopted by Apple but is an Open Standard. You can learn more about it in this blog.
Why is HEIC support important?
HEIC files are becoming increasingly common because:-
- They offer much smaller file sizes for a given quality than JPG file format
- They are the default option in the Apple Ecosystem (Macs, tablets, phones)
What libraries/ plugins to consider for HEIC support in Java?
There are a selection of Open Source and Commercial libraries which offer HEIC support to Java developers. We recommend JDeli because:-
- It can read and write HEIC files
- It offers the most complete implementation of the HEIC specification
- It is actively supported and developed
- It is pure Java, not a wrapper on a non-Java library.
- It is available as an ImageIO plugin so your existing image code will work with no changes
What is JDeli and why should you use it?
JDeli is a Java image library developed by IDRSolutions. It is designed for Java developers and is used by many global companies like Abacus, Mercedes-Benz Bank, Clearsense, USAA, etc.
JDeli is well-known for its advantage in premium support, easy integration, high security, outstanding performance, and simple pricing plan. You can read this blog to learn more about why JDeli is a great enterprise-level Java image library. It also supports other Image file formats including AVIF, JPEG, JPEG XL, TIFF, WEBP.
How to upgrade ImageIO to work with HEIC files
It’s actually very simple and can be done without rewriting your existing code!
For example, the code below does not work with ImageIO for HEIC images
// Read HEIC image into Java with ImageIO
BufferedImage bufferedImage = ImageIO.read(new File("heicImageFile.heic"));
// Write out BufferedImage as HEIC image file with ImageIO
ImageIO.write(bufferedImage, "heic", new File("heic"));
Steps to fix:
- Download the JDeli trial jar with our ImageIO plugin
- Follow the support documentation to install
Can I use JDeli directly?
You can write new code in JDeli which is designed to look like ImageIO API but adds new features
File file = new File("/path/to/outputFile.heic"));
JDeli.write(bufferedImage, "heic", file);
//In JDeli you can also use a typesafe version
JDeli.write(bufferedImage, OutputFormat.HEIC, file);
//or pass in a object for more control over Heic image output
HeicEncoderOptions options = new HeicEncoderOptions();
JDeli.write(bufferedImage, options, file);
Conclusion
Adding HEIC support in Java can be done very simply with JDeli. All you need to do is replacing ImageIO with JDeli in your codes. Click here to try it out!
Are you a Java Developer working with Image files?
// Read an image
BufferedImage bufferedImage = JDeli.read(avifImageFile);
// 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);
What is JDeli?
JDeli is a commercial Java Image library that is used to read, write, convert, manipulate and process many different image formats.
Why use JDeli?
To handle many well known formats such as JPEG, PNG, TIFF as well as newer formats like AVIF, HEIC and JPEG XL in java with no calls to any external system or third party library.
What licenses are available?
We have 3 licenses available:
Server for on premises and cloud servers, Distribution for use in a named end user applications, and Custom for more demanding requirements.
How does JDeli compare?
We work hard to make sure JDeli performance is better than or similar to other java image libraries. Check out our benchmarks to see just how well JDeli performs.