这是我保存图片的部分代码,登陆那一块在上个问题中找吧。自己多练练,大家总不能把所有代码都给你写,主要是思路。
#region 将网上的图片下载到本地
/// 从图片地址下载图片到本地磁盘
/// 图片本地磁盘地址
/// 图片网址
public static bool SaveImageFromUrl(string FileName, string Url)
{
bool value = false;
WebResponse response = null;
Stream stream = null;
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
response = request.GetResponse();
stream = response.GetResponseStream();
if (!response.ContentType.ToLower().StartsWith("text/"))
{
value = SaveBinaryFile(response, FileName);
}
}
catch (Exception e)
{
string aa = e.ToString();
}
return value;
}
// 将二进制文件保存到磁盘
private static bool SaveBinaryFile(WebResponse response, string FileName)
{
bool Value = true;
byte[] buffer = new byte[1024];
try
{
if (File.Exists(FileName))
return true;
Stream outStream = System.IO.File.Create(FileName);
Stream inStream = response.GetResponseStream();
int l;
do
{
l = inStream.Read(buffer, 0, buffer.Length);
if (l > 0)
outStream.Write(buffer, 0, l);
}
while (l > 0);
outStream.Close();
inStream.Close();
}
catch
{
Value = false;
}
return Value;
}
#endregion