给gif动画添加水印的初步实现

先贴一下效果图:
原gif图像:

添加文字水印之后的图像

HeroSoft是添加上去的水印。
处理思想:
获得gif 图像的每一桢图像,然后将其加水印,获得每一桢的延迟时间。生成一个自定义Frame对象,再处理完每一桢之后,再通过程序将这些图片加上gif 的参数信息,重新生成一个gif文件,目前生成gif部分采用ngif库,非常慢。正在寻求更好的解决办法
程序的代码为,其中有个dll引用
 1 None.gif public   static  Bitmap WaterMarkWithText(System.Drawing.Bitmap origialGif,  string  text, string  filePath)
 2 ExpandedBlockStart.gifContractedBlock.gif         dot.gif {
 3InBlock.gif            //用于存放桢
 4InBlock.gif            List<Frame> frames = new List<Frame>();
 5InBlock.gif            //如果不是gif文件,直接返回原图像
 6InBlock.gif            if (origialGif.RawFormat.Guid != System.Drawing.Imaging.ImageFormat.Gif.Guid)
 7ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 8InBlock.gif                return origialGif;
 9ExpandedSubBlockEnd.gif            }

10InBlock.gif            //如果该图像是gif文件
11InBlock.gif            foreach (Guid guid in origialGif.FrameDimensionsList)
12ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
13InBlock.gif                System.Drawing.Imaging.FrameDimension frameDimension = new System.Drawing.Imaging.FrameDimension(guid);
14InBlock.gif                int frameCount = origialGif.GetFrameCount(frameDimension);
15InBlock.gif                for (int i = 0; i < frameCount; i++)
16ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{                   
17InBlock.gif                    if (origialGif.SelectActiveFrame(frameDimension, i) == 0)
18ExpandedSubBlockStart.gifContractedSubBlock.gif                    dot.gif{
19InBlock.gif                        int delay = Convert.ToInt32(origialGif.GetPropertyItem(20736).Value.GetValue(i));
20InBlock.gif                        Image img = Image.FromHbitmap(origialGif.GetHbitmap());
21InBlock.gif                        Font font = new Font(new FontFamily("宋体"), 35.0f,FontStyle.Bold);
22InBlock.gif                        Graphics g = Graphics.FromImage(img);
23InBlock.gif                        g.DrawString(text, font, Brushes.BlanchedAlmond, new PointF(10.0f10.0f));
24InBlock.gif                        Frame frame = new Frame(img, delay);
25InBlock.gif                        frames.Add(frame);
26ExpandedSubBlockEnd.gif                    }

27ExpandedSubBlockEnd.gif                }

28InBlock.gif                Gif.Components.AnimatedGifEncoder gif = new Gif.Components.AnimatedGifEncoder();                
29InBlock.gif                gif.Start(filePath);
30InBlock.gif                gif.SetDelay(100);
31InBlock.gif                gif.SetRepeat(0);
32InBlock.gif                for (int i = 0; i < frames.Count; i++)
33ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{                   
34InBlock.gif                    gif.AddFrame(frames[i].Image);                    
35ExpandedSubBlockEnd.gif                }

36InBlock.gif                gif.Finish();
37InBlock.gif                try
38ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
39InBlock.gif                    Bitmap gifImg = (Bitmap)Bitmap.FromFile(filePath);                    
40InBlock.gif                    return gifImg;
41ExpandedSubBlockEnd.gif                }

42InBlock.gif                catch
43ExpandedSubBlockStart.gifContractedSubBlock.gif                dot.gif{
44InBlock.gif                    return origialGif;
45ExpandedSubBlockEnd.gif                }

46ExpandedSubBlockEnd.gif            }

47InBlock.gif            return origialGif;
48ExpandedBlockEnd.gif        }

目前我的实现有几个问题:
1)无法处理透明背景的gif
2)处理速度相当的慢
兄弟们,多提一些意见,解决这个问题,效率问题比较严重,目前不能达到应用的程度,就是因为太慢。每一个gif 图像生成大概得4-10s
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值