【问题标题】:Access GIF frames with C#使用 C# 访问 GIF 帧
【发布时间】:2010-10-07 03:26:23
【问题描述】:

我是 C# 的初学者。 我想知道是否有办法使用 C# 访问 GIF 动画中的不同帧。 我正在使用 Visual Studio 2008。

【问题讨论】:

    标签: c# gif animated-gif


    【解决方案1】:

    试试这个:

    using System.Drawing;    
    using System.Drawing.Imaging;
    
    Image gifImg = Image.FromFile(pathToGifFile);
    FrameDimension dimension = new FrameDimension(gifImg.FrameDimensionsList[0]);
    // Number of frames
    int frameCount = gifImg.GetFrameCount(dimension);
    // Return an Image at a certain index
    gifImg.SelectActiveFrame(dimension, index);
    

    【讨论】:

    • Image 和 FrameDimension 位于 .net 的哪个部分?
    • @aj.toulan 用于图像,System.Drawing;对于尺寸框架,System.Drawing.Imaging。
    • 只是说如果您使用的是 Visual Studio,请将光标放在不包含命名空间的类型上,然后按“Ctrl+”。 ,如果您已经在项目中添加了正确的命名空间作为参考,它将在下拉列表中为您提供一个选项来自动添加命名空间装饰。
    • SelectActiveFrame 不是返回一个整数吗?
    • @AaA 调用 SelectActiveFrame 后,您只需正常绘制或使用图像。对象的内部将确保使用指定帧的位图。
    【解决方案2】:

    有点谷歌搜索:editing animated gif's in c#

    您可以使用 Image.GetFrameCount() 和 SelectActiveFrame() 读取动画 Gif。

    【讨论】:

    • 此答案还包括有关在帧之外获取计时信息的信息
    • 一般来说,我不会推荐这个答案。您不需要在每次绘制或使用框架时都制作位图。 SelectActiveFrame 确保在绘制图像时,将使用指定的帧。
    猜你喜欢
    • 1970-01-01
    • 2012-05-07
    • 1970-01-01
    • 2019-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多