推扬网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
推扬网 门户 你问我答 查看内容

彭安平:C#中如何实现用动态图片作为背景图,如GIF格式的.

2020-8-12 14:59| 发布者: admin| 查看: 81| 评论: 0

摘要: 吴丹樱的回答: private void SetGifBackground(string gifPath) { Image gif = Image.FromFile(gifPath); System.Drawing.Imaging.FrameDimension fd = new System.Drawing.Imaging.FrameDimension(gif.FrameDimens ...

吴丹樱的回答:

private void SetGifBackground(string gifPath) { Image gif = Image.FromFile(gifPath); System.Drawing.Imaging.FrameDimension fd = new System.Drawing.Imaging.FrameDimension(gif.FrameDimensionsList[0]); int count = gif.GetFrameCount(fd); //获取帧数(gif图片可能包含多帧,其它7a686964616fe78988e69d8331333264633533格式图片一般仅一帧) Timer giftimer = new Timer(); giftimer.Interval = 100; int i = 0; Image bgImg = null; giftimer.Tick += (s, e) => { if (i >= count) { i = 0; } gif.SelectActiveFrame(fd, i); System.IO.Stream stream = new System.IO.MemoryStream(); gif.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); if (bgImg != null) { bgImg.Dispose(); } bgImg = Image.FromStream(stream); this.BackgroundImage = bgImg; i++; }; giftimer.Start(); } 给你写了个方法 在构造函数里面调用一下 记得path是本地的 不能是url 还有 你可以考虑给图放在PictureBox里面 或者使用固定的几帧非平铺模式重复的绘制 效率会更好些 具体你再优化把 我刚才测试已经OK了 记得要加分啊 10分太低了

谢馨仪的回答:

private void SetGifBackground(string gifPath) { Image gif = Image.FromFile(gifPath); System.Drawing.Imaging.FrameDimension fd = new System.Drawing.Imaging.FrameDimension(gif.FrameDimensionsList[0]); int count = gif.GetFrameCount(fd); //获取帧数(gif图片可能包含多帧,其它7a686964616fe78988e69d8331333264633533格式图片一般仅一帧) Timer giftimer = new Timer(); giftimer.Interval = 100; int i = 0; Image bgImg = null; giftimer.Tick += (s, e) => { if (i >= count) { i = 0; } gif.SelectActiveFrame(fd, i); System.IO.Stream stream = new System.IO.MemoryStream(); gif.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); if (bgImg != null) { bgImg.Dispose(); } bgImg = Image.FromStream(stream); this.BackgroundImage = bgImg; i++; }; giftimer.Start(); } 给你写了个方法 在构造函数里面调用一下 记得path是本地的 不能是url 还有 你可以考虑给图放在PictureBox里面 或者使用固定的几帧非平铺模式重复的绘制 效率会更好些 具体你再优化把 我刚才测试已经OK了 记得要加分啊 10分太低了

风云传奇的回答:

普通的图片控件就可以了,但是你如果进行其他操作,图片可能会不动,直到你的操作结束,因为涉及到多线程的问题!你可以试试! 再看看别人怎么说的。


鲜花

握手

雷人

路过

鸡蛋

最新评论

热门推荐
最新资讯

广告服务|投稿要求|禁言标准|版权说明|免责声明|手机版|小黑屋|推扬网 ( 粤ICP备18134897号 )|网站地图 | 邮箱:vayae@hotmail.com

GMT+8, 2025-5-1 15:36 , Processed in 0.061527 second(s), 30 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

返回顶部