【问题标题】:C# Tell static GIFs apart from animated onesC# 区分静态 GIF 和动画
【发布时间】:2011-02-20 09:05:22
【问题描述】:

我会保持简短;

有什么方法可以区分静态 GIF 图像和动画图像吗?我正在使用 C#。

谢谢

【问题讨论】:

    标签: c# image types gif


    【解决方案1】:

    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.");
    

    我假设您可以将其与 1 进行比较。

    【讨论】:

    • +1 小字体的硬核文章!您能否在此处粘贴代码的 sn-p 并链接到该文章?这样,如果页面或网站被删除,答案不会丢失。
    • @amelvin:好主意。我看到 jeff 已经做到了,现在 =) @jeff atwood:将变量名更改为约定的道具!
    • 感谢您在此处添加代码,该网站不再可用。
    • 如果您的目标是检测动画,那么从死像素回答是更简洁的方法。
    【解决方案2】:

    System.Drawing.ImageAnimator.CanAnimate 从 .NET 1.1 开始可用。

    来自MSDN

    返回一个布尔值,指示指定图像是否包含基于时间的帧。

    例子:

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

    【讨论】:

      猜你喜欢
      • 2017-11-10
      • 1970-01-01
      • 1970-01-01
      • 2011-02-09
      • 1970-01-01
      • 1970-01-01
      • 2021-06-05
      • 2023-03-15
      • 2019-07-21
      相关资源
      最近更新 更多