//下载图片
//return bool
///PicSourceUrl:网络图片地址, filePath:文件保存地址
public static bool DownPic(string PicSourceUrl, string filePath) { WebRequest request = WebRequest.Create(PicSourceUrl); WebResponse response = request.GetResponse(); Stream reader = response.GetResponseStream(); FileStream writer = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write); try { byte[] buff = new byte[1024]; int c = 0; //实际读取的字节数 while ((c = reader.Read(buff, 0, buff.Length)) > 0) { writer.Write(buff, 0, c); } writer.Close(); writer.Dispose(); reader.Close(); reader.Dispose(); response.Close(); } catch (Exception ex) { return false; } finally { if (writer != null) { writer.Close(); writer.Dispose(); } if (reader != null) { reader.Close(); reader.Dispose(); } if (response != null) { response.Close(); } } return true;
}