-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
575 lines (460 loc) · 21.3 KB
/
Form1.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Text;
namespace PC_Test
{
public partial class Form1 : Form
{
private Point startingPoint =new Point();
private Point movingPoint = new Point();
//private bool panning = false;
Image imgOriginal_one, imgOriginal_two;
Size originalSize;
private List<Image> loadedImages1 = new List<Image>();
private List<Image> loadedImages2 = new List<Image>();
private int currentImageIndex = 0;
OpenFileDialog OpenFileDialog1 = new OpenFileDialog();
string leftTMO_Name;
string rightTMO_Name;
string parentFolder;
string comFolder;
string tmoFolderA;
string tmoFolderB;
string tmoA_Name;
string tmoB_Name;
int combFolderIndex = 2;
bool eltm = false;
bool tmo = false;
bool firstWriteResult = false;
int eltmcnt = 0;
int tmcnt = 0;
int Nxtcnt = 0;
int imgcnt = 0;
int a;
private double ZOOMFACTOR = 1.25; // = 25% smaller or larger
private int MINMAX = 15; // 5 times bigger or smaller than the ctrl
RadioButton RadioRight = new RadioButton();
RadioButton RadioLeft = new RadioButton();
public Form1()
{
InitializeComponent();
MultiselectImage();
LeftPanel.MouseDown += new MouseEventHandler(pictureBox1_MouseDown);
LeftPanel.MouseMove += new MouseEventHandler(pictureBox1_MouseMove);
RightPanel.MouseDown += new MouseEventHandler(pictureBox1_MouseDown);
RightPanel.MouseMove += new MouseEventHandler(pictureBox1_MouseMove);
LeftPanel.MouseWheel += new MouseEventHandler(imagemPictureBox_MouseWheel);
RightPanel.MouseWheel += new MouseEventHandler(imagemPictureBox_MouseWheel);
EvaluationPanel.Visible = false;
//EvaluateResult.Enabled = false;
//a = loadedImages1.Count;
textBox1.Visible = false;
//textBox1.Text = a.ToString() + " Images Left";
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
//panning = true;
startingPoint = new Point(e.X,e.Y);
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
//panning = false;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button==System.Windows.Forms.MouseButtons.Left)
{
int X = (startingPoint.X - e.X);
int Y = (startingPoint.Y - e.Y);
LeftPanel.AutoScrollPosition =
new Point((X - LeftPanel.AutoScrollPosition.X),
(Y - LeftPanel.AutoScrollPosition.Y));
RightPanel.AutoScrollPosition =
new Point((X - RightPanel.AutoScrollPosition.X),
(Y - RightPanel.AutoScrollPosition.Y));
//movingPoint = new Point(e.Location.X - startingPoint.X,
// e.Location.Y - startingPoint.Y);
//LeftImage.Invalidate();
}
}
private void MultiselectImage()
{
// Set the file dialog to filter for graphics files.
this.OpenFileDialog1.Filter =
"Images (*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|" +
"All files (*.*)|*.*";
// Allow the user to select multiple images.
this.OpenFileDialog1.Multiselect = true;
this.OpenFileDialog1.Title = "My Image Browser";
}
private void OpenOtherTMO_Click(object sender, EventArgs e)
{
tmo = true;
DialogResult dr = this.OpenFileDialog1.ShowDialog();
if (dr == System.Windows.Forms.DialogResult.OK)
{
loadedImages2.Clear();
// Read the files
foreach (String file in OpenFileDialog1.FileNames)
{
// Create a PictureBox.
loadedImages2.Add(Image.FromFile(file));
}
if (loadedImages2.Count > 0)
{
currentImageIndex = 0;
RightImage.Image = loadedImages2[currentImageIndex];
imgOriginal_two = RightImage.Image;
}
eltmcnt = 0;
tmcnt = 0;
imgcnt = 0;
Nxtcnt = 0;
OpenOtherTMO.Enabled = false;
Start.Enabled = true;
a = loadedImages1.Count;
textBox1.Text = a.ToString() + " Images Left";
}
rightTMO_Name = Path.GetFileName(Path.GetDirectoryName(OpenFileDialog1.FileName));
firstWriteResult = true;
}
private void NextImage_Click(object sender, EventArgs e)
{
if (eltm && tmo)
{
//trackBar1.Value = 0;
if (currentImageIndex < loadedImages1.Count - 1 && currentImageIndex < loadedImages2.Count - 1)
{
currentImageIndex = currentImageIndex + 1;
RightImage.Image = loadedImages2[currentImageIndex];
imgOriginal_two = RightImage.Image;
LeftImage.Image = loadedImages1[currentImageIndex];
imgOriginal_one = LeftImage.Image;
}
else
{
currentImageIndex = 0;
RightImage.Image = loadedImages2[currentImageIndex];
imgOriginal_two = RightImage.Image;
LeftImage.Image = loadedImages1[currentImageIndex];
imgOriginal_one = LeftImage.Image;
}
}
}
private void PreImage_Click(object sender, EventArgs e)
{
if (eltm && tmo)
{
//trackBar1.Value = 0;
if (currentImageIndex > 0)
{
currentImageIndex = currentImageIndex - 1;
RightImage.Image = loadedImages2[currentImageIndex];
imgOriginal_two = RightImage.Image;
LeftImage.Image = loadedImages1[currentImageIndex];
imgOriginal_one = LeftImage.Image;
}
else
{
currentImageIndex = loadedImages1.Count - 1;
RightImage.Image = loadedImages2[currentImageIndex];
imgOriginal_two = RightImage.Image;
LeftImage.Image = loadedImages1[currentImageIndex];
imgOriginal_one = LeftImage.Image;
}
}
}
private void Start_Click(object sender, EventArgs e)
{
if (eltm && tmo)
{
textBox1.Visible = true;
if (RaLeft.Checked)
{
RaLeft.Checked = false;
}
else if (RaRight.Checked)
{
RaRight.Checked = false;
}
EvaluationPanel.Visible = true;
Label lbl = new Label();
lbl.Font = new Font("Times New Romen", 10, FontStyle.Regular);
lbl.ForeColor = Color.Black;
lbl.Size = new Size(15, 15);
lbl.AutoSize = true;
lbl.Padding = new System.Windows.Forms.Padding(20, 8, 0, 0);
lbl.Text = "Which One Image is Better Quality?";
EvaluationPanel.Controls.Add(lbl);
}
}
private void imagemPictureBox_MouseWheel(object sender, MouseEventArgs e)
{
LeftPanel.AutoScrollPosition = new Point(0, 0);
RightPanel.AutoScrollPosition = new Point(0, 0);
//_picbox2.Image = _imOriginal;
//_picbox2.SizeMode = PictureBoxSizeMode.StretchImage;
if (e.Delta < 0)
{
ZoomIn();
}
else
{
ZoomOut();
}
}
private void ZoomIn()
{
LeftImage.Location = new System.Drawing.Point(0, 0);
RightImage.Location = new System.Drawing.Point(0, 0);
if ((LeftImage.Width < (MINMAX * LeftPanel.Width)) && (LeftImage.Height < (MINMAX * LeftPanel.Height)) || (RightImage.Width < (MINMAX * RightPanel.Width)) && (RightImage.Height < (MINMAX * RightPanel.Height)))
{
LeftImage.Width = Convert.ToInt32(LeftImage.Width * ZOOMFACTOR);
LeftImage.Height = Convert.ToInt32(LeftImage.Height * ZOOMFACTOR);
LeftImage.SizeMode = PictureBoxSizeMode.StretchImage;
RightImage.Width = Convert.ToInt32(RightImage.Width * ZOOMFACTOR);
RightImage.Height = Convert.ToInt32(RightImage.Height * ZOOMFACTOR);
RightImage.SizeMode = PictureBoxSizeMode.StretchImage;
//_txtinfor.Text = "zoom in: " + _picbox.Width.ToString() + "x" + _picbox.Height.ToString() + " \t top/left" + _picbox.Top.ToString() + "x" + _picbox.Left.ToString() + "\t";
}
}
private void ZoomOut()
{
LeftImage.Location = new System.Drawing.Point(0, 0);
RightImage.Location = new System.Drawing.Point(0, 0);
if ((LeftImage.Width > (LeftPanel.Width / MINMAX)) && (LeftImage.Height > (LeftPanel.Height / MINMAX)) || (RightImage.Width > (RightPanel.Width / MINMAX)) && (RightImage.Height > (RightPanel.Height / MINMAX)))
{
LeftImage.SizeMode = PictureBoxSizeMode.StretchImage;
LeftImage.Width = Convert.ToInt32(LeftImage.Width / ZOOMFACTOR);
LeftImage.Height = Convert.ToInt32(LeftImage.Height / ZOOMFACTOR);
RightImage.SizeMode = PictureBoxSizeMode.StretchImage;
RightImage.Width = Convert.ToInt32(RightImage.Width / ZOOMFACTOR);
RightImage.Height = Convert.ToInt32(RightImage.Height / ZOOMFACTOR);
//_txtinfor.Text = "zoom out: " + _picbox.Width.ToString() + "x" + _picbox.Height.ToString() + " \t top/left" + _picbox.Top.ToString() + "x" + _picbox.Left.ToString() + "\t";
}
}
Image ZoomInOut(Image img, Size size)
{
LeftImage.SizeMode = PictureBoxSizeMode.AutoSize;
RightImage.SizeMode = PictureBoxSizeMode.AutoSize;
Bitmap bmp = new Bitmap(img, img.Width + (img.Width * size.Width / 100), img.Height + (img.Height * size.Height / 100));
Graphics graph = Graphics.FromImage(bmp);
graph.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
return bmp;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void RaLeft_CheckedChanged(object sender, EventArgs e)
{
if (currentImageIndex != loadedImages1.Count && currentImageIndex != loadedImages2.Count)
{
Left: if (RaLeft.Checked)
{
string message = "Are you sure?";
string title = "Window";
MessageBoxButtons button = MessageBoxButtons.YesNo;
DialogResult result = MessageBox.Show(message, title, button, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
a = a - 1;
textBox1.Text = a.ToString() + " Images Left";
Nxtcnt++;
//imgcnt++;
eltmcnt++;
EvaluationPanel.Visible = false;
}
else
{
eltmcnt = eltmcnt;
//imgcnt = imgcnt;
Nxtcnt = Nxtcnt;
//RadioLeft.Checked = false;
RaLeft.Checked = false;
goto Left;
}
LeftImage.SizeMode = PictureBoxSizeMode.AutoSize;
RightImage.SizeMode = PictureBoxSizeMode.AutoSize;
//trackBar1.Value = 0;
if (currentImageIndex < loadedImages1.Count - 1 && currentImageIndex < loadedImages2.Count - 1)
{
currentImageIndex = currentImageIndex + 1;
RightImage.Image = loadedImages2[currentImageIndex];
imgOriginal_two = RightImage.Image;
LeftImage.Image = loadedImages1[currentImageIndex];
imgOriginal_one = LeftImage.Image;
Nxtcnt = 0;
imgcnt++;
}
else
{
//string path = @"C:\Users\902\Desktop\PC TEST\Result.txt";
string rsltpath = Path.GetFullPath(Path.GetDirectoryName(Path.GetDirectoryName(OpenFileDialog1.FileName)));
string path = Path.Combine(rsltpath, "Result.txt");
//EvaluateResult.Enabled = true;
string msg = "Congratulation You Finish Your Evaluation! Thank You";
string ti = "Window";
MessageBoxButtons btn = MessageBoxButtons.OK;
DialogResult rslt = MessageBox.Show(msg, ti, btn, MessageBoxIcon.Information);
if (rslt == DialogResult.OK)
{
//Write Result after evaluation of each combination
if (firstWriteResult)
{
if (!File.Exists(path))
{
System.IO.StreamWriter tw = new System.IO.StreamWriter(path, true); //writing txt file
tw.WriteLine(eltmcnt + ":Images are Selected that " + leftTMO_Name + " is in good quality & \t" + tmcnt + ":Images are selected That " + rightTMO_Name + " is in good Quality");
tw.Close();
}
else if (File.Exists(path))
{
System.IO.StreamWriter tw = new System.IO.StreamWriter(path, true);
tw.WriteLine(eltmcnt + ":Images are Selected that " + leftTMO_Name + " is in good quality & \t" + tmcnt + ":Images are selected That " + rightTMO_Name + " is in good Quality");
tw.Close();
}
Dispose();
}
}
}
}
}
else
{
}
}
private void RaRight_CheckedChanged(object sender, EventArgs e)
{
if (currentImageIndex != loadedImages1.Count && currentImageIndex != loadedImages2.Count )
{
Right: if (RaRight.Checked)
{
string message = "Are you sure?";
string title = "Window";
MessageBoxButtons button = MessageBoxButtons.YesNo;
DialogResult result = MessageBox.Show(message, title, button, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
a = a - 1;
textBox1.Text = a.ToString() + " Images Left";
Nxtcnt++;
//imgcnt++;
tmcnt++;
EvaluationPanel.Visible = false;
}
else
{
tmcnt = tmcnt;
//imgcnt = imgcnt;
Nxtcnt = Nxtcnt;
RaRight.Checked = false;
goto Right;
}
LeftImage.SizeMode = PictureBoxSizeMode.AutoSize;
RightImage.SizeMode = PictureBoxSizeMode.AutoSize;
//trackBar1.Value = 0;
if (currentImageIndex < loadedImages1.Count - 1 && currentImageIndex < loadedImages2.Count - 1)
{
currentImageIndex = currentImageIndex + 1;
RightImage.Image = loadedImages2[currentImageIndex];
imgOriginal_two = RightImage.Image;
LeftImage.Image = loadedImages1[currentImageIndex];
imgOriginal_one = LeftImage.Image;
Nxtcnt = 0;
imgcnt++;
}
else
{
string rsltpath = Path.GetFullPath(Path.GetDirectoryName(Path.GetDirectoryName(OpenFileDialog1.FileName)));
string path = Path.Combine(rsltpath, "Result.txt");
string msg = "Congratulation You Finish Your Evaluation! Thank You";
string ti = "Result Window";
MessageBoxButtons btn = MessageBoxButtons.OK;
DialogResult rslt = MessageBox.Show(msg, ti, btn, MessageBoxIcon.Information);
if (rslt == DialogResult.OK)
{
if (firstWriteResult)
{
if (!File.Exists(path))
{
System.IO.StreamWriter tw = new System.IO.StreamWriter(path, true); //writing txt file
tw.WriteLine(eltmcnt + ":Images are Selected that " + leftTMO_Name + " is in good quality & \t" + tmcnt + ":Images are selected That " + rightTMO_Name + " is in good Quality");
tw.Close();
}
else if (File.Exists(path))
{
System.IO.StreamWriter tw = new System.IO.StreamWriter(path, true);
tw.WriteLine(eltmcnt + ":Images are Selected that " + leftTMO_Name + " is in good quality & \t" + tmcnt + ":Images are selected That " + rightTMO_Name + " is in good Quality");
tw.Close();
}
Dispose();
}
tmcnt = 0;
eltmcnt = 0;
combFolderIndex++;
imgcnt = 0;
firstWriteResult = false;
}
else
{
}
}
}
}
else
{
//EvaluateResult.Enabled = true;
}
}
private void EvaluationPanel_Paint(object sender, PaintEventArgs e)
{
}
private void LeftImage_Click(object sender, EventArgs e)
{
}
private void OpenELTM_Click(object sender, EventArgs e)
{
eltm = true;
DialogResult dr = this.OpenFileDialog1.ShowDialog();
if (dr == System.Windows.Forms.DialogResult.OK)
{
loadedImages1.Clear();
// Read the files
foreach (String file in OpenFileDialog1.FileNames)
{
// Create a PictureBox.
loadedImages1.Add(Image.FromFile(file));
}
if (loadedImages1.Count > 0)
{
currentImageIndex = 0;
LeftImage.Image = loadedImages1[currentImageIndex];
imgOriginal_one = LeftImage.Image;
}
eltmcnt = 0;
tmcnt = 0;
imgcnt = 0;
Nxtcnt = 0;
OpenELTM.Enabled = false;
Start.Enabled = true;
}
//leftTMO_Name = Path.GetFileNameWithoutExtension(OpenFileDialog1.FileName);
leftTMO_Name = Path.GetFileName(Path.GetDirectoryName(OpenFileDialog1.FileName));
firstWriteResult = true;
//string name = Path.GetFileNameWithoutExtension(OpenFileDialog1.FileName);
//string name = Path.GetFullPath(Path.GetDirectoryName(Path.GetDirectoryName(OpenFileDialog1.FileName)));
//string path = Path.Combine(name, "Result.txt");
//string ti = "Result Window";
//MessageBoxButtons btn = MessageBoxButtons.OK;
//MessageBox.Show(path, ti, btn, MessageBoxIcon.Question);
}
}
}