当前位置:编程学习 > C#/ASP.NET >>

保存远程图片

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(); //释放资源
}

}

 摘自 小白白小

补充:软件开发 , C# ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,