using System;
using System.Drawing;
using System.IO;
using System.Net;
/// <summary>
/// 图片操作
/// </summary>
public class ImageDownload
{
/// <summary>
/// 从网络下载图片并保存到指定路径
/// </summary>
/// <param name="param_WebImageUrl">图片网络Url</param>
/// <param name="param_Localpath">本地路径</param>
/// <param name="param_SavaImageFileNmae">图片名称</param>
public void DownloadImageAndSavaToLoca(string param_WebImageUrl, string param_Localpath, string param_SavaImageFileNmae)
{
WebRequest ImageResqust = WebRequest.Create(param_WebImageUrl);
HttpWebResponse res;
try
{
res = (HttpWebResponse)ImageResqust.GetResponse();
}
catch (WebException ex)
{
res = (HttpWebResponse)ex.Response;
}
try
{
//图片下载成功
if (res.StatusCode.ToString() == "OK")
{//以流的方式保存图片
Image downimage = Image.FromStream(ImageResqust.GetResponse().GetResponseStream());
//------保存图片到本地------
if (!Directory.Exists(param_Localpath))
{
Directory.CreateDirectory(param_Localpath);
}
downimage.Save(param_Localpath + param_SavaImageFileNmae);
downimage.Dispose();
}
}
catch (Exception ex)
{
}
}
}