2012年2月29日星期三

保存图片

System.Drawing.Image image = null;
try
{
string fileName = imgs[i];
string filePath = commonpath + imgs[i];
string localFile = localpath + imgs[i];

HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(filePath);
HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse();
if (webresponse.StatusCode == HttpStatusCode.OK)
{
image = System.Drawing.Image.FromStream(webresponse.GetResponseStream());
//保存在服务器的本地硬盘

image.Save(localFile);

//保存在客户端上

File.WriteAllBytes(@"D:\1.JPG",byteImage);

}
}
catch (Exception ex)
{
string result = "远程图片保存失败,原因为:\n" + ex.Message;
Response.Write(result);
Response.End();
break;
}
finally
{
if (image != null)
{
image.Dispose(); //释放资源
}

}


保存图片

TAG: