/// <summary>
/// 判断文件夹是否存在网络图片
/// </summary>
/// <param name="localUrl">需要判断的本地文件夹</param>
/// <param name="netUrl">网络文件地址</param>
/// <returns></returns>
public bool ImageCompare(string saveImgPath, string netUrl,out string fullName)
{
fullName = string.Empty;
bool b = false;
DateTime dt = DateTime.Now;
var defUrl = ConfigurationBase.Default.UploadFilePath.TrimEnd('/', '\\');
var localUrl = defUrl + $"{saveImgPath}{dt.Year}/{dt.ToString("MM")}";
try
{
var images = Directory.GetFiles(localUrl, ".", SearchOption.AllDirectories).Where(x => x.ToLower().EndsWith(".png") || x.ToLower().EndsWith(".jpg"));
if (images.Count() > 0)
{
WebClient mywebclient = new WebClient();
byte[] netBytes = mywebclient.DownloadData(netUrl);
string secondBitmap = Convert.ToBase64String(netBytes);
foreach (var image in images)
{
if (File.Exists(image))
{
using (FileStream fsRead = new FileStream(image, FileMode.Open, FileAccess.Read))
{
//创建缓冲区的大小
byte[] buffer = new byte[fsRead.Length];
//调用对象的读取数据的方法
int r = fsRead.Read(buffer, 0, buffer.Length);
//将字节转换成字符串
string firstBitmap = Convert.ToBase64String(buffer);
if (firstBitmap.Equals(secondBitmap)) { b = true; fullName = fsRead.Name.Replace(defUrl, string.Empty); break; }
}
}
}
}
else
{
b= false;
fullName = string.Empty;
}
}
catch (Exception ex)
{
_logger.Error(ex.ToString());
}
return b;
}