package nvgif - Java bindings for nvgif.c¶
Source: c/java/nvgif/NVGIFDecoder.java
There is a Java binding for the C implementation. As such, it only supports v1–v3.
It uses Java Native Access (JNA) to call the C dynamic library. It is not considered its own reference implementation because it is simply a binding, nothing more.
To use it, you must download the c/ folder and follow the instructions in the README to build the Java bindings.
After that’s done, copy everything inside java/dist to your project.
- public class NVGIFDecoder¶
- public static java.awt.image.BufferedImage decode(String filename)¶
Decodes the image at
filenameand returns it in the form of aBufferedImage. Under the hood, it usesnvg_decode_imageto decode the image, transforms it into aBufferedImage, and then callsnvg_free_imageto free the CImagestructure.
Example
import nvgif.NVGIFDecoder;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.File;
public class NVGIFTest {
public static void main(String[] args) throws Exception {
if (args.length < 2) {
System.err.println("Usage: NVGIFTest input.nvg output.png");
return;
}
BufferedImage img = NVGIFDecoder.decode(args[0]);
ImageIO.write(img, "png", new File(args[1]));
System.out.println("Decoded " + args[0] + " and wrote " + args[1]);
}
}