Understand an gif is animated or not in JAVA

半世苍凉 提交于 2019-12-07 12:24:20

问题


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?


回答1:


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();
        }  
}


来源:https://stackoverflow.com/questions/22221528/understand-an-gif-is-animated-or-not-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!