@@ -14,10 +14,10 @@ namespace SimilarImages
1414 public partial class Form1 : Form
1515 {
1616 private string folderPath = Environment . GetFolderPath ( Environment . SpecialFolder . Desktop ) ;
17- private int precision = 20 ;
18- private int threshold = 80 ;
19- private ImageHash . HashEnum hashEnum = ImageHash . HashEnum . Difference ;
20- private InterpolationMode interpolationMode = InterpolationMode . Default ;
17+ private int precision ;
18+ private int threshold ;
19+ private ImageHash . HashEnum hashEnum ;
20+ private InterpolationMode interpolationMode ;
2121 private List < Tuple < string , string , double > > tuples = null ;
2222 private readonly bool isSimplifiedChinese = CultureInfo . CurrentUICulture . Name == "zh-CN" ;
2323
@@ -36,6 +36,8 @@ private void Form1_SizeChanged(object sender, EventArgs e)
3636
3737 private void Form1_Load ( object sender , EventArgs e )
3838 {
39+ tkb_Precision . Value = 20 ;
40+ tkb_Threshold . Value = 80 ;
3941 cmb_Algorithm . SelectedIndex = 0 ;
4042 cmb_Interpolation . SelectedIndex = 0 ;
4143 tb_Directory . Text = folderPath ;
@@ -56,15 +58,6 @@ private void btn_Directory_Click(object sender, EventArgs e)
5658 folderPath = fbd . SelectedPath ;
5759 }
5860
59- private void Form1_DragDrop ( object sender , DragEventArgs e )
60- {
61- if ( e . Data . GetDataPresent ( DataFormats . FileDrop ) )
62- {
63- tb_Directory . Text = ( ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ) [ 0 ] ;
64- folderPath = tb_Directory . Text ;
65- }
66- }
67-
6861 private void Form1_DragEnter ( object sender , DragEventArgs e )
6962 {
7063 if ( e . Data . GetDataPresent ( DataFormats . FileDrop ) )
@@ -79,27 +72,12 @@ private void Form1_DragEnter(object sender, DragEventArgs e)
7972 e . Effect = DragDropEffects . None ;
8073 }
8174
82- private void tb_Threshold_KeyPress ( object sender , KeyPressEventArgs e )
83- {
84- // Allow 0-9, backspace
85- if ( ( e . KeyChar < '0' || e . KeyChar > '9' ) && e . KeyChar != '\b ' )
86- { e . Handled = true ; }
87- }
88-
89- private void cmb_Algorithm_SelectedIndexChanged ( object sender , EventArgs e )
90- {
91- hashEnum = ( ImageHash . HashEnum ) cmb_Algorithm . SelectedIndex ;
92- }
93-
94- private void cmb_Interpolation_SelectedIndexChanged ( object sender , EventArgs e )
75+ private void Form1_DragDrop ( object sender , DragEventArgs e )
9576 {
96- switch ( cmb_Interpolation . SelectedIndex )
77+ if ( e . Data . GetDataPresent ( DataFormats . FileDrop ) )
9778 {
98- case 0 : interpolationMode = InterpolationMode . Default ; break ;
99- case 1 : interpolationMode = InterpolationMode . NearestNeighbor ; break ;
100- case 2 : interpolationMode = InterpolationMode . HighQualityBilinear ; break ;
101- case 3 : interpolationMode = InterpolationMode . HighQualityBicubic ; break ;
102- default : break ;
79+ tb_Directory . Text = ( ( string [ ] ) e . Data . GetData ( DataFormats . FileDrop ) ) [ 0 ] ;
80+ folderPath = tb_Directory . Text ;
10381 }
10482 }
10583
@@ -122,6 +100,18 @@ private void tkb_Precision_MouseHover(object sender, EventArgs e)
122100 toolTip1 . SetToolTip ( ( Control ) sender , tip ) ;
123101 }
124102
103+ private void cmb_Interpolation_SelectedIndexChanged ( object sender , EventArgs e )
104+ {
105+ switch ( cmb_Interpolation . SelectedIndex )
106+ {
107+ case 0 : interpolationMode = InterpolationMode . Default ; break ;
108+ case 1 : interpolationMode = InterpolationMode . NearestNeighbor ; break ;
109+ case 2 : interpolationMode = InterpolationMode . HighQualityBilinear ; break ;
110+ case 3 : interpolationMode = InterpolationMode . HighQualityBicubic ; break ;
111+ default : break ;
112+ }
113+ }
114+
125115 private void cmb_Interpolation_MouseHover ( object sender , EventArgs e )
126116 {
127117 string tip = "The interpolation mode when resizing images." ;
@@ -132,6 +122,11 @@ private void cmb_Interpolation_MouseHover(object sender, EventArgs e)
132122 toolTip1 . SetToolTip ( ( Control ) sender , tip ) ;
133123 }
134124
125+ private void cmb_Algorithm_SelectedIndexChanged ( object sender , EventArgs e )
126+ {
127+ hashEnum = ( ImageHash . HashEnum ) cmb_Algorithm . SelectedIndex ;
128+ }
129+
135130 private void cmb_Algorithm_MouseHover ( object sender , EventArgs e )
136131 {
137132 string tip = "The algorithm when calculating image hashes." ;
@@ -174,14 +169,12 @@ private void btn_Process_Click(object sender, EventArgs e)
174169 precision = tkb_Precision . Value ;
175170 threshold = tkb_Threshold . Value ;
176171
177- bool validFolderPath = ! string . IsNullOrEmpty ( tb_Directory . Text ) &&
178- Directory . Exists ( tb_Directory . Text ) ;
179- string tip = "Please input valid folder path." ;
172+ string tip = "Directory does not exist." ;
180173 if ( isSimplifiedChinese )
181174 {
182- tip = "请输入合适的文件夹路径 。" ;
175+ tip = "文件夹不存在 。" ;
183176 }
184- if ( ! AssertConfig ( validFolderPath , tip ) ) { return ; }
177+ if ( ! AssertConfig ( Directory . Exists ( tb_Directory . Text ) , tip ) ) { return ; }
185178
186179 // Dispose previous items
187180 pictureBox1 . Image ? . Dispose ( ) ;
0 commit comments