-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResizeDialog.cs
170 lines (151 loc) · 5.57 KB
/
ResizeDialog.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
using Emgu.CV.CvEnum;
namespace CyberedgeImageProcess2024
{
public partial class ResizeDialog : Form
{
public Emgu.CV.CvEnum.Inter Interpolation = Emgu.CV.CvEnum.Inter.Linear;
public int newWidth, newHeight;
private double xScale = 0.5, yScale = 0.5;
private int origWidth, origHeight;
public string NewWindowTitle
{
get { return txtNewWindowTitle.Text; }
set { txtNewWindowTitle.Text = PublicFunctions.GetUniqueName(value); }
}
public bool BoolCreateNewWindow
{
get { return chkCreateNewWindow.Checked; }
}
public double XScale
{
get { return xScale; }
}
public double YScale
{
get { return yScale; }
}
public ResizeDialog()
{
InitializeComponent();
cbInterpolation.SelectedIndex = (int)Inter.Linear;
}
private void cbInterpolation_SelectedIndexChanged(object sender, EventArgs e)
{
Interpolation = (Emgu.CV.CvEnum.Inter)cbInterpolation.SelectedIndex;
}
private void chkAspect_CheckedChanged(object sender, EventArgs e)
{
if (chkAspect.Checked)
{
UpdateTextBox();
}
}
private void UpdateTextBox()
{
txtScaleY.Text = txtScaleX.Text;
yScale = xScale;
newHeight = (int)Math.Round(origHeight * yScale);
txtHeight.Text = newHeight.ToString();
}
private void txtWidth_TextChanged(object sender, EventArgs e)
{
double newXScale = xScale;
double newYScale = yScale;
if (sender == txtScaleX && txtScaleX.Focused)
{
String newXText = txtScaleX.Text;
newXScale = PublicFunctions.ConvertStringToDouble(newXText, 0);
if (newXScale == 0) return;
if (newXScale != xScale)
{
newWidth = (int)Math.Round(newXScale * origWidth);
txtWidth.Text = newWidth.ToString();
if (chkAspect.Checked)
{
txtScaleY.Text = txtScaleX.Text;
newHeight = (int)Math.Round(newXScale * origHeight);
txtHeight.Text = newHeight.ToString();
newYScale = newXScale;
}
}
}
else if (sender == txtScaleY && txtScaleY.Focused)
{
String newYText = txtScaleY.Text;
newYScale = PublicFunctions.ConvertStringToDouble(newYText, 0);
if (newYScale == 0) return;
if (newYScale != yScale)
{
newHeight = (int)Math.Round(newYScale * origHeight);
txtHeight.Text = newHeight.ToString();
if (chkAspect.Checked)
{
txtScaleX.Text = txtScaleY.Text;
newWidth = (int)Math.Round(newYScale * origWidth);
txtWidth.Text = newWidth.ToString();
newXScale = newYScale;
}
}
}
else if (sender == txtWidth && txtWidth.Focused)
{
newWidth = (int)Math.Round(PublicFunctions.ConvertStringToDouble(txtWidth.Text, 0.0));
if (newWidth != 0)
{
newXScale = 1.0 * newWidth / origWidth;
txtScaleX.Text = newXScale.ToString("F2");
if (chkAspect.Checked)
{
txtScaleY.Text = txtScaleX.Text;
newHeight = (int)Math.Round(newXScale * origHeight);
txtHeight.Text = newHeight.ToString();
newYScale = newXScale;
}
}
}
else if (sender == txtHeight && txtHeight.Focused)
{
newHeight = (int)Math.Round(PublicFunctions.ConvertStringToDouble(txtHeight.Text, 0.0));
if (newHeight != 0)
{
newYScale = 1.0 * newHeight / origHeight;
txtScaleY.Text = newYScale.ToString("F2");
if (chkAspect.Checked)
{
txtScaleX.Text = txtScaleY.Text;
newWidth = (int)Math.Round(newYScale * origWidth);
txtWidth.Text = newWidth.ToString();
newXScale = newYScale;
}
}
}
xScale = newXScale;
yScale = newYScale;
}
private void btnOK_Click(object sender, EventArgs e)
{
Close();
}
private void btnCancle_Click(object sender, EventArgs e)
{
Close();
}
private void chkCreateNewWindow_CheckedChanged(object sender, EventArgs e)
{
txtNewWindowTitle.Visible = chkCreateNewWindow.Checked;
lblNewWindowTitle.Visible = chkCreateNewWindow.Checked;
}
private void ResizeDialog_Load(object sender, EventArgs e)
{
}
public void SetSize(int width, int height)
{
origWidth = width;
origHeight = height;
newWidth = (width / 2);
txtWidth.Text = newWidth.ToString();
newHeight = (height / 2);
txtHeight.Text = newHeight.ToString();
}
}
}