public static bool ImageCompareString(Bitmap firstImage, Bitmap secondImage)
{
MemoryStream ms = new MemoryStream();
firstImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
String firstBitmap = Convert.ToBase64String(ms.ToArray());
ms.Position = 0;
secondImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
String secondBitmap = Convert.ToBase64String(ms.ToArray());
if (firstBitmap.Equals(secondBitmap))
{
return true;
}
else
{
return false;
}
}
使用範例"指定路徑圖片判斷是否一致"
PictureBox pb = new PictureBox();
PictureBox pb2 = new PictureBox();
string str = Directory.GetCurrentDirectory() + "\\1.jpg";
string str2 = Directory.GetCurrentDirectory() + "\\2.jpg";
pb.Load(str);
pb2.Load(str2);
Bitmap bmp1 = new Bitmap(pb.Image);
Bitmap bmp2 = new Bitmap(pb2.Image);
bool Result = false;
Result = ImageCompareString(bmp1, bmp2);
沒有留言:
張貼留言