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.

How to write HEIC image files in Java (Tutorial)

1 min read

heic file icon

how to write heic image (heic icon)

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.

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


Steps to fix:

How to write an image as a Heic file with JDeli

  1. Add JDeli to your class or module path. (download the trial jar).
  2. Create a File (or OutputStream) object
  3. Pass image, Heic type, and File (or OutputStream) object into write method

and the Java code to write Heic with JDeli…


 

Other useful HEIC links



Are you a Java Developer working with Image files?

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.