开发者

C# Tell static GIFs apart from animated ones

开发者 https://www.devze.com 2022-12-30 19:02 出处:网络
I\'ll keep it short and simple; is there any way of telling static GIF images apart from animated ones? I\'m开发者_如何转开发 using C#.

I'll keep it short and simple;

is there any way of telling static GIF images apart from animated ones? I'm开发者_如何转开发 using C#.

Thanks


Here's an article about how to determine the number of frames in a GIF animation.

Image i = Image.FromFile(Server.MapPath("AnimatedGIF.gif"));

Imaging.FrameDimension FrameDimensions = 
    new Imaging.FrameDimension(i.FrameDimensionsList[0]);

int frames = i.GetFrameCount(FrameDimensions);

if (frames > 1) 
    Response.Write("Image is an animated GIF with " + frames + " frames");
else 
    Response.Write("Image is not an animated GIF.");

And I assume you could just compare that with 1.


System.Drawing.ImageAnimator.CanAnimate has been available since .NET 1.1.

From MSDN:

Returns a Boolean value indicating whether the specified image contains time-based frames.

Example:

using (Image image = Image.FromFile("somefile.gif"))
{
    if (ImageAnimator.CanAnimate(image))
    {
        // GIF is animated
    }
    else
    {
        // GIF is not animated
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消