Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Tell static GIFs apart from animated ones

Tags:

c#

types

image

gif

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

like image 390
pastapockets Avatar asked May 17 '10 11:05

pastapockets


2 Answers

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.

like image 180
David Hedlund Avatar answered Sep 24 '22 18:09

David Hedlund


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
    }
}
like image 28
deadpixel Avatar answered Sep 24 '22 18:09

deadpixel