artwl
artwl

Reputation: 3582

Get a gif picture from website but after save it become a static picture

i Get a gif picture from website but after save it become a static picture,my code is:

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();

who can help me? thanks!

Upvotes: 0

Views: 255

Answers (1)

Icarus
Icarus

Reputation: 63962

Do this instead:

   using (WebClient wc = new WebClient())
   {
      wc.DownloadFile("http://www.ifanr.com/wp-content/uploads/2011/10/J1D2AYQV.gif", @"D:\test.gif");
   }

Your gif image will be kept intact.

Upvotes: 2

Related Questions