c# 如何比较两幅图片是否相同 最好能实际给出代码 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 转换为RGB数据流进行比较把.. private bool ImageEquals(Bitmap bmpOne,Bitmap bmpTwo) { for (int i = 0; i < bmpOne.Width; i++) { for (int j = 0; j < bmpOne.Height; j++) { if (bmpOne.GetPixel(i, j) != bmpTwo.GetPixel(i, j)) return false; } } return true; } private bool ScanBitmap(Bitmap SourceBitmap, Bitmap TargetBitmap){ BitmapData bmpDATA1 = new BitmapData(); SourceBitmap.LockBits(new Rectangle(0, 0, SourceBitmap.Width, SourceBitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); BitmapData bmpDATA2 = new BitmapData(); TargetBitmap.LockBits(new Rectangle(0, 0, TargetBitmap.Width, TargetBitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); byte[] BTS1 = new byte[bmpDATA1.Stride * bmpDATA1.Height + 1]; byte[] BTS2 = new byte[bmpDATA2.Stride * bmpDATA2.Height + 1]; System.Runtime.InteropServices.Marshal.Copy(bmpDATA1.Scan0, BTS1, 0, BTS1.Length); System.Runtime.InteropServices.Marshal.Copy(bmpDATA2.Scan0, BTS2, 0, BTS2.Length); if (BTS1.Length != BTS2.Length) { return false; SourceBitmap.UnlockBits(bmpDATA1); SourceBitmap.UnlockBits(bmpDATA2); Interaction.MsgBox("两图不同!"); return; } for (int I = 0; I <= BTS1.Length - 1; I += 4) { if (BTS1[I] != BTS2[I] || BTS1[I + 1] != BTS1[I + 1] || BTS1[I + 2] != BTS1[I + 2] || BTS1[I + 3] != BTS1[I + 3]) { return false; SourceBitmap.UnlockBits(bmpDATA1); SourceBitmap.UnlockBits(bmpDATA2); Interaction.MsgBox("两图不同!"); return; } } return true; SourceBitmap.UnlockBits(bmpDATA1); SourceBitmap.UnlockBits(bmpDATA2); Interaction.MsgBox("两图完全一样");}//参数说明: //SourceBitmap:要比较的源图 //TargetBitmap:要比较的条件图 http://topic.csdn.net/u/20081230/12/6c3e1e10-8c62-49dd-b899-9d51abc4f02c.html 如要定位像素位置将i,j换个位置if (bmpOne.GetPixel(j, i) != bmpTwo.GetPixel(j, i)) return false; Bitmap Image_One = new Bitmap(@"C:\Documents and Settings\helang\桌面 \ImageEquals\one.jpg", true); Bitmap Image_two = new Bitmap(@"C:\Documents and Settings\helang\桌面\ImageEquals\two.jpg", true); private bool ImageEquals(Bitmap bmpOne, Bitmap bmpTwo) { for (int i = 0; i < bmpOne.Width; i++) { for (int j = 0; j < bmpOne.Height; j++) { if (bmpOne.GetPixel(i, j) != bmpTwo.GetPixel(i, j)) return false; } } return true; } private void button1_Click(object sender, EventArgs e) { if (ImageEquals(Image_One, Image_two)) { MessageBox.Show("完全一样!"); } else { MessageBox.Show("不同!"); } } 将两张图片转换成 int[,,],然后相减,在另一个数组里标识出非0的区域即可 C# winform 设计时和运行时 用C#做一个任务调度工具 关于水晶报表问题 大家帮我看一下以下SQL语句有什么错误,谢谢! 一个扩大静态GIF画布问题 C#来从从图像中找到一特定点 winfrom中treeview选中某一节点显示背影色问题 求C#初学者必看之程序 高分求教。sourcesafe中签出后产生的问题。 有没有如何使用visual studio.net的电子书介绍一下,谢谢! Hashtable Dictionary 多线程性能 模拟键盘做个@符号输入
private bool ImageEquals(Bitmap bmpOne,Bitmap bmpTwo)
{
for (int i = 0; i < bmpOne.Width; i++)
{
for (int j = 0; j < bmpOne.Height; j++)
{
if (bmpOne.GetPixel(i, j) != bmpTwo.GetPixel(i, j))
return false;
}
}
return true;
}
{
BitmapData bmpDATA1 = new BitmapData();
SourceBitmap.LockBits(new Rectangle(0, 0, SourceBitmap.Width, SourceBitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
BitmapData bmpDATA2 = new BitmapData();
TargetBitmap.LockBits(new Rectangle(0, 0, TargetBitmap.Width, TargetBitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
byte[] BTS1 = new byte[bmpDATA1.Stride * bmpDATA1.Height + 1];
byte[] BTS2 = new byte[bmpDATA2.Stride * bmpDATA2.Height + 1];
System.Runtime.InteropServices.Marshal.Copy(bmpDATA1.Scan0, BTS1, 0, BTS1.Length);
System.Runtime.InteropServices.Marshal.Copy(bmpDATA2.Scan0, BTS2, 0, BTS2.Length);
if (BTS1.Length != BTS2.Length) {
return false;
SourceBitmap.UnlockBits(bmpDATA1);
SourceBitmap.UnlockBits(bmpDATA2);
Interaction.MsgBox("两图不同!");
return;
}
for (int I = 0; I <= BTS1.Length - 1; I += 4) {
if (BTS1[I] != BTS2[I] || BTS1[I + 1] != BTS1[I + 1] || BTS1[I + 2] != BTS1[I + 2] || BTS1[I + 3] != BTS1[I + 3]) {
return false;
SourceBitmap.UnlockBits(bmpDATA1);
SourceBitmap.UnlockBits(bmpDATA2);
Interaction.MsgBox("两图不同!");
return;
}
}
return true;
SourceBitmap.UnlockBits(bmpDATA1);
SourceBitmap.UnlockBits(bmpDATA2);
Interaction.MsgBox("两图完全一样");
}//参数说明:
//SourceBitmap:要比较的源图
//TargetBitmap:要比较的条件图
如要定位像素位置将i,j换个位置
if (bmpOne.GetPixel(j, i) != bmpTwo.GetPixel(j, i))
return false;
Bitmap Image_two = new Bitmap(@"C:\Documents and Settings\helang\桌面\ImageEquals\two.jpg", true); private bool ImageEquals(Bitmap bmpOne, Bitmap bmpTwo)
{
for (int i = 0; i < bmpOne.Width; i++)
{
for (int j = 0; j < bmpOne.Height; j++)
{
if (bmpOne.GetPixel(i, j) != bmpTwo.GetPixel(i, j))
return false;
}
}
return true;
} private void button1_Click(object sender, EventArgs e)
{
if (ImageEquals(Image_One, Image_two))
{
MessageBox.Show("完全一样!");
}
else
{
MessageBox.Show("不同!");
}
}
在另一个数组里标识出非0的区域即可