彭安平:C#中如何实现用动态图片作为背景图,如GIF格式的.
吴丹樱的回答:
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分太低了
风云传奇的回答:
普通的图片控件就可以了,但是你如果进行其他操作,图片可能会不动,直到你的操作结束,因为涉及到多线程的问题!你可以试试! 再看看别人怎么说的。