代码如下:
string picurl = "http://www.ifanr.com/wp-content/uploads/2011/10/J1D2AYQV.gif";
string savepath=@"D:\test.gif";
string imgExt = picurl.Substring(picurl.LastIndexOf("."), picurl.Length - picurl.LastIndexOf("."));
WebRequest wreq = WebRequest.Create(picurl);
wreq.Timeout = 10000;
HttpWebResponse wresp = (HttpWebResponse)wreq.GetResponse();
Stream s = wresp.GetResponseStream();
System.Drawing.Image img = System.Drawing.Image.FromStream(s);
if (imgExt == ".gif")
{
img.Save(savepath, ImageFormat.Gif);
}
img.Dispose();
s.Dispose();
请教高人,为什么动成的gif图片保存为本地gif图片后成静态的了?
using (WebClient wc = new WebClient())
{
wc.DownloadFile(picurl, savepath);
}
你那是下载了第一帧的图,当然是静态的了。可以这样下载的。
string picurl = "http://www.ifanr.com/wp-content/uploads/2011/10/J1D2AYQV.gif";
string savepath = @"D:\test.gif";
string imgExt = picurl.Substring(picurl.LastIndexOf("."), picurl.Length - picurl.LastIndexOf("."));
if (imgExt == ".gif")
{
using (WebClient wc = new WebClient())
{
try
{
wc.DownloadFile(picurl, savepath);
MessageBox.Show("文件下载成功!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
谢谢,后来自己找到答案了