大马资讯论坛 - 马来西亚中文资讯平台
标题:
C# 图片对比是否一样,Comparing Two picture/images-教学
[打印本页]
作者:
资讯王
时间:
2012-6-27 22:17
标题:
C# 图片对比是否一样,Comparing Two picture/images-教学
C# 图片对比是否一样,Comparing Two picture/images-教学
使用Byte Array做对比,Use Byte Array for picture/image comparison
private bool ImageCompareArray(Bitmap firstImage, Bitmap secondImage)
{
bool flag = true;
string firstPixel;
string secondPixel;
if (firstImage.Width == secondImage.Width
&& firstImage.Height == secondImage.Height)
{
for (int i = 0; i < firstImage.Width; i++)
{
for (int j = 0; j < firstImage.Height; j++)
{
firstPixel = firstImage.GetPixel(i, j).ToString();
secondPixel = secondImage.GetPixel(i, j).ToString();
if (firstPixel != secondPixel)
{
flag = false;
break;
}
}
}
if (flag == false)
{
return false;
}
else
{
return true;
}
}
else
{
return false;
}
}
复制代码
使用Base 64做对比,Use Base 64 for picture/image comparison
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;
}
}
复制代码
欢迎光临 大马资讯论坛 - 马来西亚中文资讯平台 (http://freeinfo.com.my/)
Powered by Discuz! X3.3