我从网站上获取了一张GIF图片,但保存后它变为静态图片,我的代码是:
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();
谁可以帮助我?谢谢!
答案 0 :(得分:2)
请改为:
using (WebClient wc = new WebClient())
{
wc.DownloadFile("http://www.ifanr.com/wp-content/uploads/2011/10/J1D2AYQV.gif", @"D:\test.gif");
}
您的gif图片将保持不变。