1、使用了OpencvSharp,进行图片的存储,所以项目需要引入OpencvSharp的包。
2、准备好从别的数据库获得的图像url的txt,每行一个url地址。
参考代码如下:
string txt = @"C:\\Users\\zyh\\Desktop\\test.txt";
int name = 1000;
Mat mat;
StreamReader sr = new StreamReader(txt, Encoding.Default);
string content;
while ((content = sr.ReadLine()) != null)
{
try
{
System.Net.WebClient webClient = new System.Net.WebClient();
System.IO.Stream stream = webClient.OpenRead(@content.ToString());
if (stream != null)
{
mat = OpenCvSharp.Extensions.BitmapConverter.ToMat(new Bitmap(Image.FromStream(stream)));
Cv2.ImWrite("C:\\Users\\zyh\\Desktop\\r_g_pic\\" + name + ".jpg", mat);
stream.Dispose();
name++;
}
Console.WriteLine(content.ToString());
}
catch (Exception)
{
}
}