Why do HEIC Images cause problems for Java Developers?
ImageIO does not write HEIC file types by default so existing Java Applications will not work with them. This is an increasing problem as HEIC images are becoming increasingly widespread. It is the default file format for the Apple Ecosystem and offers significant advantages over established formats such as JPG.
// 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
}
In this post, I will cover how to use JDeli to add HEIC support to existing Java Applications which use ImageIO (without having to make any code changes) and how to write out images as HEIC files in JDeli directly.
What options are there for supporting HEIC files in Java?
Java does not support HEIC images by default so you will need to use an external library or plugin. There are a range of Open Source and Commercial options available, including Java wrappers on non-Java solutions.
If you are looking for a free solution, we recommend the Nokia library on GitHub (which includes Java wrappers).
We recommend JDeli because it is a pure, complete Java implementation which can also read HEIC files. It can be used with existing ImageIO code and has an API to write new code so we will document that in this article. It also supports several other Image formats.
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 without the JDeli plugin
// 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("output.heic"));
Steps to fix:
- Download the JDeli trial jar with our ImageIO plugin
- Follow the support documentation to install
How to write an image as a Heic file with JDeli
- Add JDeli to your class or module path. (download the trial jar).
- Create a File (or OutputStream) object
- Pass image, Heic type, and File (or OutputStream) object into write method
and the Java code to write Heic with JDeli…
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);
Other useful HEIC links
- JDeli HEIC support
- Related articles on our support site.
- How to read HEIC files in Java.
- How to convert HEIC to JPG in bulk (Tutorial)
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.