/
ImageChecker.cs
77 lines (69 loc) · 1.44 KB
/
ImageChecker.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
using System;
using System.Drawing;
using System.IO;
public class ImageChecker
{
public static void Main(String[] args)
{
// Compare args[0] and args[1]
// If they are very similar delete args[0]
Bitmap imgOne = new Bitmap(Image.FromFile(args[0]));
Bitmap imgTwo = new Bitmap(Image.FromFile(args[1]));
if(ImgCompare(imgOne, imgTwo))
{
File.Delete(args[0]);
Console.WriteLine("ImageChecker deleted the older image!");
}
}
private static bool ImgCompare(Bitmap one, Bitmap two)
{
if(one.Width == two.Width && one.Height == two.Height)
{
int count = 0;
for(int i = 0; i < one.Width; i++)
{
for(int j = 0; j < one.Height; j++)
{
Color oneColor = one.GetPixel(i, j);
Color twoColor = two.GetPixel(i, j);
if(!SimilarColors(oneColor, twoColor))
{
count++;
}
}
}
Console.WriteLine(count);
if(count <=15000)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
private static bool SimilarColors(Color colorOne, Color colorTwo)
{
if (Math.Abs(colorOne.GetHue()-colorTwo.GetHue()) <= 36)
{
//Console.WriteLine("Hue");
return true;
}
if (Math.Abs(colorOne.GetBrightness()-colorTwo.GetBrightness()) <= .1)
{
//Console.WriteLine("Hue");
return true;
}
if (Math.Abs(colorOne.GetSaturation()-colorTwo.GetSaturation()) <= .1)
{
//Console.WriteLine("Hue");
return true;
}
return false;
}
}