您当前位置:编程帮手 > 知识 > 知识 > C# > Image > 内容
代码库
2015-12-03 15:45:33 访问(5163) 赞(0) 踩(0)
/// <summary> /// 远程下载图片 /// </summary> /// <param name="webSaveUrl"></param> /// <param name="imageUrl"></param> /// <returns></returns> protected bool DownLoadImage ( string webSaveUrl, string imageUrl ) { string saveName = Request.PhysicalApplicationPath + webSaveUrl; FileInfo theInfo = new FileInfo(saveName); if (theInfo.Exists) return false; if (!theInfo.Directory.Exists) theInfo.Directory.Create(); WebClient my = null; MemoryStream ms = null; System.Drawing.Image img = null; try { // 利用 WebClient 类 my = new WebClient(); byte[] mybyte = null; mybyte = my.DownloadData(imageUrl); ms = new MemoryStream(mybyte); img = System.Drawing.Image.FromStream(ms); // 保存 // img.Save(theInfo.FullName); return true; } catch { return false; } finally { if (img != null) { img.Dispose(); img = null; } if (ms != null) { ms.Dispose(); ms = null; } if (my != null) { my.Dispose(); my = null; } } }
上一条:
下一条: