Skip to content

Commit 90f232c

Browse files
Zixu_WangZixu_Wang
authored andcommitted
Change threshold textbox to percentage format and highlight better resolution.
1 parent 0afb0e8 commit 90f232c

File tree

8 files changed

+772
-851
lines changed

8 files changed

+772
-851
lines changed

SimilarImages/SimilarImages/Form1.Designer.cs

Lines changed: 17 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SimilarImages/SimilarImages/Form1.cs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public partial class Form1 : Form
1616
{
1717
private string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
1818
private int precision = 20;
19-
private double threshold = 0.8;
19+
private int threshold = 80;
2020
private ImageHash.HashEnum hashEnum = ImageHash.HashEnum.Difference;
2121
private InterpolationMode interpolationMode = InterpolationMode.Default;
2222
private List<Tuple<string, string, double>> tuples = null;
@@ -60,14 +60,9 @@ private void tb_Precision_KeyPress(object sender, KeyPressEventArgs e)
6060

6161
private void tb_Threshold_KeyPress(object sender, KeyPressEventArgs e)
6262
{
63-
// Allow 0-9, backspace and '.'
64-
if ((e.KeyChar < '0' || e.KeyChar > '9') &&
65-
e.KeyChar != '\b' && e.KeyChar != '.')
63+
// Allow 0-9, backspace
64+
if ((e.KeyChar < '0' || e.KeyChar > '9') && e.KeyChar != '\b')
6665
{ e.Handled = true; }
67-
// Only one '.'
68-
if (tb_Threshold.Text.Contains('.') && e.KeyChar == '.') { e.Handled = true; }
69-
// '.' can only come after '0'
70-
if (tb_Threshold.Text == "0" && e.KeyChar != '.') { e.Handled = true; }
7166
}
7267

7368
private void cmb_Algorithm_SelectedIndexChanged(object sender, EventArgs e)
@@ -123,13 +118,13 @@ private void cmb_Algorithm_Click(object sender, EventArgs e)
123118

124119
private void tb_Threshold_Click(object sender, EventArgs e)
125120
{
126-
string tip = "Range: 0-1.\n" +
121+
string tip = "Range: 0-99%.\n" +
127122
"Usage: Return results greater than the threshold.\n" +
128123
"Notice: Don't set a low threshold when processing mass images, " +
129124
"as the operation will take too long.";
130125
if (isSimplifiedChinese)
131126
{
132-
tip = "范围:0-1\n" +
127+
tip = "范围:0-99%\n" +
133128
"用途:返回大于阈值的结果。\n" +
134129
"注意:当图片数量较多时,不要使用低阈值,以免耗时太长。";
135130
}
@@ -143,25 +138,25 @@ private void tb_Threshold_Click(object sender, EventArgs e)
143138
private void btn_Process_Click(object sender, EventArgs e)
144139
{
145140
bool validPrecision = int.TryParse(tb_Precision.Text, out precision);
146-
bool validThreshold = double.TryParse(tb_Threshold.Text, out threshold);
147-
bool validFolderPath = !string.IsNullOrEmpty(tb_Directory.Text);
141+
bool validThreshold = int.TryParse(tb_Threshold.Text, out threshold);
142+
bool validFolderPath = !string.IsNullOrEmpty(tb_Directory.Text) && Directory.Exists(tb_Directory.Text);
148143

149144
string tip1 = "Please input valid precision.";
150145
string tip2 = "Precision should be greater than 8.";
151-
string tip3 = "Please input valid threshold (0,1).";
146+
string tip3 = "Please input valid threshold (0,99).";
152147
string tip4 = "Please input valid folder path.";
153148
if (isSimplifiedChinese)
154149
{
155150
tip1 = "请输入合适的精度值。";
156151
tip2 = "精度值需要大于 8。";
157-
tip3 = "请输入合适的阈值 (0,1)。";
152+
tip3 = "请输入合适的阈值 (0,99)。";
158153
tip4 = "请输入合适的文件夹路径。";
159154
}
160155

161-
if (!AssertConfig(validPrecision, tip1)) { return; }
162-
if (!AssertConfig(precision >= 8, tip2)) { return; }
163-
if (!AssertConfig(validThreshold, tip3)) { return; }
164-
if (!AssertConfig(threshold > 0 && threshold < 1, tip3)) { return; }
156+
if (!AssertConfig(validPrecision, tip1)) { tb_Precision.Text = "20"; return; }
157+
if (!AssertConfig(precision >= 8, tip2)) { tb_Precision.Text = "20"; return; }
158+
if (!AssertConfig(validThreshold, tip3)) { tb_Threshold.Text = "80"; return; }
159+
if (!AssertConfig(threshold > 0 && threshold < 100, tip3)) { tb_Threshold.Text = "80"; return; }
165160
if (!AssertConfig(validFolderPath, tip4)) { return; }
166161

167162
progressBar1.Visible = true;
@@ -250,6 +245,18 @@ private void lvw_Result_SelectedIndexChanged(object sender, EventArgs e)
250245
lb_Image2.Text = "Deleted";
251246
lb_Resolution2.Text = "";
252247
}
248+
249+
if (pictureBox1.Image.Width * pictureBox1.Image.Height >=
250+
pictureBox2.Image.Width * pictureBox2.Image.Height)
251+
{
252+
lb_Resolution1.ForeColor = Color.Green;
253+
lb_Resolution2.ForeColor = Color.Black;
254+
}
255+
else
256+
{
257+
lb_Resolution1.ForeColor = Color.Black;
258+
lb_Resolution2.ForeColor = Color.Green;
259+
}
253260
}
254261

255262
private void btn_Delete1_Click(object sender, EventArgs e)

0 commit comments

Comments
 (0)