Domanda

I have a gif image and I would like to be able to detect whether the gif is an animated gif or not using JAVA. This question is about detection rather than displaying the gif.

I see that MIME type of animated gif isn't different of static gif.

How I can do it?

È stato utile?

Soluzione

You need an ImageReader. if size is 1 its not animated, everything above is animated. Check this out:

public Snippet() {
        File f = new File("test.gif");
        ImageReader is = ImageIO.getImageReadersBySuffix("GIF").next();  
        ImageInputStream iis;
        try {
            iis = ImageIO.createImageInputStream(f);
            is.setInput(iis);  
            int images= is.getNumImages(true);
        } catch (IOException e) {
            e.printStackTrace();
        }  
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top