用Image类的Save(saveFileName, ImageFormat.Gif)方法保存的虽然后缀名为gif,但实际上依然是静态图(打开只有一帧,不会动)
WebClient的DownloadFile或者DownloadFileAsync方法可以保存为真正的gif,但是WebClient类没有WebRequest灵活,所以想请教如果用WebRequest下载gif图片,该怎么保存呢?谢谢
------解决方案--------------------------------------------------------
http://blog.csdn.net/xiaofengsheng/article/details/4642990
------解决方案--------------------------------------------------------
/// <summary>
/// 下载
/// </summary>
/// <param name="URL">网址</param>
/// <param name="Filename">文件名</param>
/// <returns>True/False是否下载成功</returns>
public bool DownLoadFile(string URL, string Filename, ProgressBar Prog)
{
try
{
System.Net.HttpWebRequest Myrq = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(URL); //从URL地址得到一个WEB请求
Myrq.Proxy = WebRequest.DefaultWebProxy;
Myrq.Proxy.Credentials = new NetworkCredential();
System.Net.HttpWebResponse myrp = (System.Net.HttpWebResponse)Myrq.GetResponse(); //从WEB请求得到WEB响应
long totalBytes = myrp.ContentLength; //从WEB响应得到总字节数
Prog.Maximum = (int)totalBytes; //从总字节数得到进度条的最大值
System.IO.Stream st = myrp.GetResponseStream(); //从WEB请求创建流(读)
System.IO.Stream so = new System.IO.FileStream(Filename, System.IO.FileMode.Create); //创建文件流(写)
long totalDownloadedByte = 0; //下载文件大小
byte[] by = new byte[1024];
int osize = st.Read(by, 0, (int)by.Length); //读流
while (osize > 0)
{
totalDownloadedByte = osize + totalDownloadedByte; //更新文件大小
Application.DoEvents();