首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >NGif动画器背景问题

NGif动画器背景问题
EN

Stack Overflow用户
提问于 2011-11-02 00:06:53
回答 1查看 872关注 0票数 1

我一直在玩NGif Animator来调整动画gif的大小,它确实可以调整大小,但我尝试过的许多动画gif中的部分都被擦除了。我浏览了那个页面上的评论,没有看到其他人提到它。

为了消除由于调整大小的原因,我简单地循环遍历框架并保存每个框架。每一帧都是一个System.Drawing.Image。透明度设置为none (Color.Empty)。

这是我目前的测试方法:

代码语言:javascript
复制
        GifDecoder gifDecoder = new GifDecoder();
        MemoryStream memoryStream = new MemoryStream();
        new BinaryWriter((Stream)memoryStream).Write(imageToResize); // byte array
        memoryStream.Position = 0L;

        gifDecoder.Read((Stream)memoryStream);
        memoryStream.Dispose();

        string filename = Guid.NewGuid().ToString().Replace("-", String.Empty) + ".gif";
        string output = path + @"\" + filename;

        AnimatedGifEncoder animatedGifEncoder = new AnimatedGifEncoder();
        animatedGifEncoder.Start(output);
        animatedGifEncoder.SetRepeat(gifDecoder.GetLoopCount());
        animatedGifEncoder.SetQuality(10); // They say 20 is max quality will get, I've tried higher.  Makes it a little bit better but black areas instead of gray. 10 is their default.
        animatedGifEncoder.SetTransparent(Color.Empty); // This is default either way

        int frameCount = gifDecoder.GetFrameCount();
        int num = 0;

        Image frame;
        Image image = null;

        for (int index = frameCount; num < index; ++num)
        {
            frame = gifDecoder.GetFrame(num);
            animatedGifEncoder.SetDelay(gifDecoder.GetDelay(num));

            string fname = @"C:\Development\images\frame_" + num.ToString() + ".gif";
            if (File.Exists(fname)) { File.Delete(fname); }
            frame.Save(fname);

            animatedGifEncoder.AddFrame(image);
        }

        animatedGifEncoder.Finish();

以下是正在发生的情况的一个示例:

背景消失了,它是灰色的。

它应该看起来像这样:

有没有人有过使用NGif的经验,知道什么会导致这种情况?第一帧总是可以的。在那之后的其他人都有问题,所以我猜有些东西没有从一帧到另一帧被重置(或重新读取)。我已经在他们的重置框架方法中添加了更多的东西,但到目前为止还没有帮助。现在看起来是这样的:

代码语言:javascript
复制
    protected void ResetFrame() 
    {
        lastDispose = dispose;
        lastRect = new Rectangle(ix, iy, iw, ih);
        lastImage = image;
        lastBgColor = bgColor;

        delay = 0;
        transparency = false; // I don't want transparency
        lct = null;
        act = null;
        transIndex = -1;
    }
EN

回答 1

Stack Overflow用户

发布于 2013-08-01 03:27:27

实际上,他们的代码中有一个bug,一个字节数组没有被重置。查看他们页面上的评论以获得解决方案

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7969287

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档