【问题标题】:Get a gif picture from website but after save it become a static picture从网站获取gif图片,但保存后变成静态图片
【发布时间】:2011-12-09 00:42:53
【问题描述】:

我从网站上获取了一张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();

谁能帮助我?谢谢!

【问题讨论】:

  • 什么是“静态图片”?没有动画帧的 GIF?
  • 不要将其转换为Image,而是将二进制流直接保存到您的文件中。

标签: .net asp.net image gif


【解决方案1】:

改为这样做:

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

您的 gif 图像将保持原样。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-28
    • 2013-07-03
    • 2011-05-19
    • 2015-11-11
    • 2018-03-24
    • 1970-01-01
    • 1970-01-01
    • 2018-08-15
    相关资源
    最近更新 更多