foreach (string imageurl in urls)
{
Console.WriteLine(imageurl);
byte[] imageData = null;
try
{
imageData = client.DownloadData(imageurl);
}
catch { }
if (imageData != null && imageData.Length>0)
using (MemoryStream ms = new MemoryStream(imageData))
{
try
{
string ext = Aping.Utility.File.FileOpration.ExtendName(imageurl);
ImageFormat format = ImageFormat.Jpeg;
switch (ext)
{
case ".jpg":
format = ImageFormat.Jpeg;
break;
case ".bmp":
format = ImageFormat.Bmp;
break;
case ".png":
format = ImageFormat.Png;
break;
case ".gif":
format = ImageFormat.Gif;
break;
case ".ico":
format = ImageFormat.Icon;
break;
default:
continue;
}
Image image = new Bitmap(ms);
if (Directory.Exists(path))
image.Save(path + "//" + cursor + ext, format);
}
catch(Exception ex) { Console.WriteLine(ex.Message); }
}
cursor++;
}
mstream.Close();
File.WriteAllText(countFile, cursor.ToString(), Encoding.UTF8);
Console.WriteLine("take done...image count:"+(cursor-oldCount).ToString());
}
}
新闻热点
疑难解答