2011-10-17 33 views
0

我從網站上的GIF圖片,但保存後變成靜態圖片後,我的代碼是:獲取一個GIF圖片,但保存成爲靜態圖片

string picurl = "http://www.ifanr.com/wp-content/uploads/2011/10/J1D2AYQV.gif"; 
string [email protected]"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

什麼是「靜態圖片」?一個沒有動畫幀的GIF? –

+1

Do _not_不會將其轉換爲'Image',而是將二進制流直接保存到您的文件中。 –

回答

2

而是執行此操作:

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

你的GIF圖像將保持不變。