-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.cs
90 lines (80 loc) · 2.57 KB
/
code.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace ImageCompareEqualsCSharp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Bitmap firstImage = new Bitmap(@"D:\Desktop\pictureOne.png");
Bitmap secondImage = new Bitmap(@"D:\Desktop\pictureTwo.png");
// bool isEqual = ImageCompareString(firstImage, secondImage);
bool isEqual = ImageCompareArray(firstImage, secondImage);
if (isEqual)
{
MessageBox.Show("The image is equal 100%");
}
else
{
MessageBox.Show("The image is different.");
}
}
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;
}
}
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;
}
}
}
}