ep1:
ep2:
实现原理:
通过读取图片,把图片转为base64后进行对比即可达到目的。
以下是图片转base64的方法:
public string GetBase64StringByImage(Image img){string base64buffer = string.Empty;try{if (img != null){byte[] bytes = PhotoImageInsert(img);base64buffer = Convert.ToBase64String(bytes);}}catch (Exception ex){ }return base64buffer;}//将Image转换成流数据,并保存为byte[] public byte[] PhotoImageInsert(Image imgPhoto){MemoryStream mstream = new MemoryStream();imgPhoto.Save(mstream, System.Drawing.Imaging.ImageFormat.Bmp);byte[] byData = new Byte[mstream.Length];mstream.Position = 0;mstream.Read(byData, 0, byData.Length); mstream.Close();return byData;}
调用方法:
if (pictureBox1.Image == null || pictureBox2.Image == null){MessageBox.Show("请先选择两张图片!");return;}string str1 = GetBase64StringByImage(pictureBox1.Image),str2 = GetBase64StringByImage(pictureBox2.Image);MessageBox.Show(str1 == str2 ? "图片完全相同!" : "图片不相同");