Class AnimatedWebPDecoder

java.lang.Object
dev.matrixlab.webp4j.animation.AnimatedWebPDecoder

public final class AnimatedWebPDecoder extends Object
Decoder for extracting individual frames from animated WebP images.

This class uses the libwebp WebPAnimDecoder API to decode animated WebP images into individual frames as BufferedImage objects with their timestamps.

Example usage:


 byte[] webPData = Files.readAllBytes(Paths.get("animation.webp"));
 AnimatedWebPData result = AnimatedWebPDecoder.decode(webPData);
 for (AnimatedWebPFrame frame : result.getFrames()) {
     BufferedImage image = frame.getImage();
     int timestamp = frame.getTimestamp();
 }
 int[] delays = result.getDelays(); // per-frame delays in ms
 
Author:
MrNanko
  • Method Details

    • decode

      public static AnimatedWebPData decode(byte[] webPData) throws IOException
      Decodes an animated WebP image into individual frames.

      Each frame is a fully composited canvas-sized RGBA BufferedImage. The returned AnimatedWebPData contains all frames with their timestamps, as well as animation metadata (canvas size, loop count, etc.).

      Parameters:
      webPData - Byte array containing the animated WebP image data
      Returns:
      AnimatedWebPData containing all decoded frames and metadata
      Throws:
      IOException - If decoding fails
      IllegalArgumentException - If webPData is null or empty