没有别的办法,只能靠数据流读取图片再转化为字节数组进行比对。分享一下。
private bool Same(Image image1, Image image2)
{MemoryStream ms1 = new MemoryStream();
MemoryStream ms2 = new MemoryStream();
image1.Save(ms1, System.Drawing.Imaging.ImageFormat.Bmp);
image2.Save(ms2, System.Drawing.Imaging.ImageFormat.Bmp);
byte[] im1 = ms1.GetBuffer();
byte[] im2 = ms2.GetBuffer();
if (im1.Length != im2.Length)
return false;
else
{
for (int i = 0; i < im1.Length; i++)
if (im1[i] != im2[i])
return false;
}
return true;
}