栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > asp

.net c# gif动画如何添加图片水印实现思路及代码

asp 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

.net c# gif动画如何添加图片水印实现思路及代码

复制代码 代码如下:
public static Bitmap WaterMarkWithText(System.Drawing.Bitmap origialGif, string
text,string filePath)
{
//用于存放桢
List frames = new
List();
//如果不是gif文件,直接返回原图像
if (origialGif.RawFormat.Guid
!= System.Drawing.Imaging.ImageFormat.Gif.Guid)
{
return origialGif;

}
//如果该图像是gif文件
foreach (Guid guid in
origialGif.frameDimensionsList)
{
System.Drawing.Imaging.frameDimension
frameDimension = new System.Drawing.Imaging.frameDimension(guid);
int
frameCount = origialGif.GetframeCount(frameDimension);
for (int i = 0; i
< frameCount; i++)
{
if (origialGif.SelectActiveframe(frameDimension,
i) == 0)
{
int delay =
Convert.ToInt32(origialGif.GetPropertyItem(20736).Value.GetValue(i));
Image
img = Image.FromHbitmap(origialGif.GetHbitmap());
Font font = new Font(new
FontFamily("宋体"), 35.0f,FontStyle.Bold);
Graphics g =
Graphics.FromImage(img);
g.DrawString(text, font, Brushes.BlanchedAlmond,
new PointF(10.0f, 10.0f));
frame frame = new frame(img, delay);

frames.Add(frame);
}
}
Gif.Components.AnimatedGifEncoder gif =
new Gif.Components.AnimatedGifEncoder();
gif.Start(filePath);

gif.SetDelay(100);
gif.SetRepeat(0);
for (int i = 0; i <
frames.Count; i++)
{
gif.Addframe(frames[i].Image);
}

gif.Finish();
try
{
Bitmap gifImg =
(Bitmap)Bitmap.FromFile(filePath);
return gifImg;
}
catch
{

return origialGif;
}
}
return origialGif;
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/57907.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号