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图片可能包含多帧,其它格式图片一般仅一帧)
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分太低了
温馨提示:内容为网友见解,仅供参考
第1个回答  2011-04-19
普通的图片控件就可以了,但是你如果进行其他操作,图片可能会不动,直到你的操作结束,因为涉及到多线程的问题!你可以试试!
相似回答