Bethan Palmer Bethan is a Java developer and a Java Champion. She has spoken at conferences including JavaOne/Code One, DevFest and NetBeans days. She has a degree in English Literature.

How to read WebP files in Java

52 sec read

WebP file iconIn this article, I will show you how to read WebP files in Java.

ImageIO and JAI do not have support for reading the WebP file format. In order to do so you need to find a third party library, for example luciad or JDeli. Due to this lack of support, we decided write our own WebP Decoder which is available as part of JDeli.

First an introduction to WebP images…

What is WebP?

WebP images were created by Google to work on web browsers. They are designed to be small and therefore fast to load, using both lossy and lossless compression. You can read more about the WebP image format in our previous article here.

To read a webp image using a third party library such as luciad:

BufferedImage image = ImageIO.read(new File("input.webp"));

To read a webp file using JDeli (Javadoc and download):

//Read Image (can also be OutputStream or byte array)
File webpFile = new File("webpImage.webp"); 
BufferedImage image = JDeli.read(webpFile);

Or you can use the JDeli WebpDecoder directly:

WebpDecoder decoder = new WebpDecoder();
BufferedImage image = decoder.read(webpByteData);

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

Learn more about JDeli, or download to try it yourself.

This article is part of our series on reading and writing image files in Java.

Bethan Palmer Bethan is a Java developer and a Java Champion. She has spoken at conferences including JavaOne/Code One, DevFest and NetBeans days. She has a degree in English Literature.

Leave a Reply

Your email address will not be published. Required fields are marked *

IDRsolutions Ltd 2019. All rights reserved.