OtherControl.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using PaintDotNet.Base.SettingModel;
  11. using System.Collections;
  12. using PaintDotNet.ImageCollect;
  13. using PaintDotNet.Camera;
  14. namespace PaintDotNet.Preview2
  15. {
  16. /// <summary>
  17. /// 相机设置,常规界面
  18. /// </summary>
  19. public class OtherControl : UserControl
  20. {
  21. #region 控件
  22. private GroupBox gbxShadingCorrection;
  23. private GroupBox gbxSharpening;
  24. #endregion
  25. /// <summary>
  26. /// 相机参数的Model
  27. /// </summary>
  28. private CameraParamModel.ParameterSets _settings
  29. {
  30. get
  31. {
  32. return CameraConfigs.Settings;
  33. }
  34. }
  35. private ICamera m_camera => CameraManager.CurrentCamera;
  36. private CameraParamBar2 pmbSharpness;
  37. private Button btnCapTempl;
  38. private CheckBox checkBox1;
  39. private RadioButton radioButton2;
  40. private Button button1;
  41. private Panel panel1;
  42. private RadioButton radioButton1;
  43. public OtherControl()
  44. {
  45. InitializeComponent();
  46. }
  47. public void Initialize()
  48. {
  49. InitializeLanguageText();
  50. InitializeData();
  51. }
  52. /// <summary>
  53. /// 绑定样式数据
  54. /// </summary>
  55. private void InitializeData()
  56. {
  57. if (m_camera.IsOpen())
  58. {
  59. Range range = m_camera.GetSharpnessRange();
  60. pmbSharpness.DecimalPalces = 0;
  61. pmbSharpness.Max = (int)range.Max;
  62. pmbSharpness.Min = (int)range.Min;
  63. pmbSharpness.Value = _settings.Sharpness;
  64. pmbSharpness.OnValueChange += (value) => { m_camera.Sharpness = value; };
  65. UpdateSettings();
  66. }
  67. checkBox1.Checked = Preview2Context.ShandingCorrectionState != 0;
  68. radioButton1.Checked = Preview2Context.ShandingCorrectionState == 1;
  69. radioButton2.Checked = Preview2Context.ShandingCorrectionState == 2;
  70. }
  71. public void UpdateSettings()
  72. {
  73. checkBox1.Checked = _settings.FlatFieldCorrection != 0;
  74. checkBox1_CheckedChanged(null, null);
  75. radioButton1.Checked = _settings.FlatFieldCorrection == 1;
  76. radioButton2.Checked = _settings.FlatFieldCorrection == 2;
  77. radioButton2_CheckedChanged(null, null);
  78. }
  79. #region 初始化组件
  80. private void InitializeLanguageText()
  81. {
  82. this.gbxShadingCorrection.Text = PdnResources.GetString("Menu.Image.ShadingCorrection.Text");
  83. this.gbxSharpening.Text = PdnResources.GetString("Menu.Imagesharpening.text");
  84. pmbSharpness.Caption = PdnResources.GetString("Menu.Sharpeningstrength.text");
  85. this.checkBox1.Text = PdnResources.GetString("Preview2.EnableShadowCorrection");
  86. this.radioButton2.Text =PdnResources.GetString("Preview2.CameraCorrection");
  87. this.radioButton1.Text = PdnResources.GetString("Preview2.SoftwareCorrection");
  88. this.button1.Text = PdnResources.GetString("Menu.compute.text");
  89. this.btnCapTempl.Text = PdnResources.GetString("Preview2.ShootingCorrectionTemplate");
  90. }
  91. /// <summary>
  92. /// 初始化组件
  93. /// </summary>
  94. private void InitializeComponent()
  95. {
  96. this.gbxShadingCorrection = new System.Windows.Forms.GroupBox();
  97. this.panel1 = new System.Windows.Forms.Panel();
  98. this.button1 = new System.Windows.Forms.Button();
  99. this.btnCapTempl = new System.Windows.Forms.Button();
  100. this.radioButton2 = new System.Windows.Forms.RadioButton();
  101. this.radioButton1 = new System.Windows.Forms.RadioButton();
  102. this.checkBox1 = new System.Windows.Forms.CheckBox();
  103. this.gbxSharpening = new System.Windows.Forms.GroupBox();
  104. this.pmbSharpness = new PaintDotNet.Preview2.CameraParamBar2();
  105. this.gbxShadingCorrection.SuspendLayout();
  106. this.panel1.SuspendLayout();
  107. this.gbxSharpening.SuspendLayout();
  108. this.SuspendLayout();
  109. //
  110. // gbxShadingCorrection
  111. //
  112. this.gbxShadingCorrection.Controls.Add(this.panel1);
  113. this.gbxShadingCorrection.Controls.Add(this.checkBox1);
  114. this.gbxShadingCorrection.Dock = System.Windows.Forms.DockStyle.Bottom;
  115. this.gbxShadingCorrection.Location = new System.Drawing.Point(0, 67);
  116. this.gbxShadingCorrection.Name = "gbxShadingCorrection";
  117. this.gbxShadingCorrection.Size = new System.Drawing.Size(470, 95);
  118. this.gbxShadingCorrection.TabIndex = 2;
  119. this.gbxShadingCorrection.TabStop = false;
  120. this.gbxShadingCorrection.Text = "阴影校正";
  121. //
  122. // panel1
  123. //
  124. this.panel1.Controls.Add(this.button1);
  125. this.panel1.Controls.Add(this.btnCapTempl);
  126. this.panel1.Controls.Add(this.radioButton2);
  127. this.panel1.Controls.Add(this.radioButton1);
  128. this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom;
  129. this.panel1.Location = new System.Drawing.Point(3, 42);
  130. this.panel1.Name = "panel1";
  131. this.panel1.Size = new System.Drawing.Size(464, 50);
  132. this.panel1.TabIndex = 6;
  133. //
  134. // button1
  135. //
  136. this.button1.Location = new System.Drawing.Point(221, 26);
  137. this.button1.Name = "button1";
  138. this.button1.Size = new System.Drawing.Size(59, 23);
  139. this.button1.TabIndex = 5;
  140. this.button1.Text = "计算";
  141. this.button1.UseVisualStyleBackColor = true;
  142. this.button1.Click += new System.EventHandler(this.button1_Click);
  143. //
  144. // btnCapTempl
  145. //
  146. this.btnCapTempl.Location = new System.Drawing.Point(103, 26);
  147. this.btnCapTempl.Name = "btnCapTempl";
  148. this.btnCapTempl.Size = new System.Drawing.Size(112, 23);
  149. this.btnCapTempl.TabIndex = 2;
  150. this.btnCapTempl.Text = "拍摄校正模板";
  151. this.btnCapTempl.UseVisualStyleBackColor = true;
  152. this.btnCapTempl.Click += new System.EventHandler(this.btnCapTempl_Click);
  153. //
  154. // radioButton2
  155. //
  156. this.radioButton2.AutoSize = true;
  157. this.radioButton2.Location = new System.Drawing.Point(26, 29);
  158. this.radioButton2.Name = "radioButton2";
  159. this.radioButton2.Size = new System.Drawing.Size(71, 16);
  160. this.radioButton2.TabIndex = 4;
  161. this.radioButton2.Text = "相机校正";
  162. this.radioButton2.UseVisualStyleBackColor = true;
  163. this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged);
  164. this.radioButton2.Click += new System.EventHandler(this.radioButton2_Click);
  165. //
  166. // radioButton1
  167. //
  168. this.radioButton1.AutoSize = true;
  169. this.radioButton1.Checked = true;
  170. this.radioButton1.Location = new System.Drawing.Point(26, 7);
  171. this.radioButton1.Name = "radioButton1";
  172. this.radioButton1.Size = new System.Drawing.Size(71, 16);
  173. this.radioButton1.TabIndex = 4;
  174. this.radioButton1.TabStop = true;
  175. this.radioButton1.Text = "软件校正";
  176. this.radioButton1.UseVisualStyleBackColor = true;
  177. this.radioButton1.Click += new System.EventHandler(this.radioButton1_Click);
  178. //
  179. // checkBox1
  180. //
  181. this.checkBox1.AutoSize = true;
  182. this.checkBox1.Location = new System.Drawing.Point(18, 20);
  183. this.checkBox1.Name = "checkBox1";
  184. this.checkBox1.Size = new System.Drawing.Size(96, 16);
  185. this.checkBox1.TabIndex = 3;
  186. this.checkBox1.Text = "启用阴影校正";
  187. this.checkBox1.UseVisualStyleBackColor = true;
  188. this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
  189. this.checkBox1.Click += new System.EventHandler(this.checkBox1_Click);
  190. //
  191. // gbxSharpening
  192. //
  193. this.gbxSharpening.Controls.Add(this.pmbSharpness);
  194. this.gbxSharpening.Dock = System.Windows.Forms.DockStyle.Top;
  195. this.gbxSharpening.Location = new System.Drawing.Point(0, 8);
  196. this.gbxSharpening.Name = "gbxSharpening";
  197. this.gbxSharpening.Padding = new System.Windows.Forms.Padding(4);
  198. this.gbxSharpening.Size = new System.Drawing.Size(470, 52);
  199. this.gbxSharpening.TabIndex = 3;
  200. this.gbxSharpening.TabStop = false;
  201. this.gbxSharpening.Text = "图像锐化";
  202. //
  203. // pmbSharpness
  204. //
  205. this.pmbSharpness.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
  206. this.pmbSharpness.Caption = "锐化强度";
  207. this.pmbSharpness.DecimalPalces = -1;
  208. this.pmbSharpness.Dock = System.Windows.Forms.DockStyle.Top;
  209. this.pmbSharpness.IsFloat = false;
  210. this.pmbSharpness.IsRangeVisible = false;
  211. this.pmbSharpness.Location = new System.Drawing.Point(4, 18);
  212. this.pmbSharpness.Max = 100;
  213. this.pmbSharpness.Min = 0;
  214. this.pmbSharpness.Name = "pmbSharpness";
  215. this.pmbSharpness.Padding = new System.Windows.Forms.Padding(4);
  216. this.pmbSharpness.Size = new System.Drawing.Size(462, 26);
  217. this.pmbSharpness.TabIndex = 0;
  218. this.pmbSharpness.Value = 0;
  219. //
  220. // OtherControl
  221. //
  222. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
  223. this.Controls.Add(this.gbxShadingCorrection);
  224. this.Controls.Add(this.gbxSharpening);
  225. this.Name = "OtherControl";
  226. this.Padding = new System.Windows.Forms.Padding(0, 8, 0, 0);
  227. this.Size = new System.Drawing.Size(470, 162);
  228. this.gbxShadingCorrection.ResumeLayout(false);
  229. this.gbxShadingCorrection.PerformLayout();
  230. this.panel1.ResumeLayout(false);
  231. this.panel1.PerformLayout();
  232. this.gbxSharpening.ResumeLayout(false);
  233. this.ResumeLayout(false);
  234. }
  235. #endregion
  236. private void metroButton1_Click(object sender, EventArgs e)
  237. {
  238. }
  239. private void btnCapTempl_Click(object sender, EventArgs e)
  240. {
  241. m_camera.FlatCapture();
  242. }
  243. private void radioButton2_Click(object sender, EventArgs e)
  244. {
  245. m_camera.FlatCorretion = 1;
  246. Preview2Context.ShandingCorrectionState = 2;
  247. }
  248. private void radioButton1_Click(object sender, EventArgs e)
  249. {
  250. m_camera.FlatCorretion = 0;
  251. Preview2Context.ShandingCorrectionState = 1;
  252. }
  253. private void button1_Click(object sender, EventArgs e)
  254. {
  255. m_camera.FlatCalculate();
  256. Preview2Context.ShandingCorrectionState = 2;
  257. }
  258. private void checkBox1_Click(object sender, EventArgs e)
  259. {
  260. if (checkBox1.Checked)
  261. {
  262. if (radioButton1.Checked)
  263. { Preview2Context.ShandingCorrectionState = 1; }
  264. else if (radioButton2.Checked)
  265. {
  266. Preview2Context.ShandingCorrectionState = 0;
  267. m_camera.FlatCorretion = 1;
  268. }
  269. }
  270. else
  271. {
  272. Preview2Context.ShandingCorrectionState = 0;
  273. m_camera.FlatCorretion = 0;
  274. }
  275. }
  276. private void checkBox1_CheckedChanged(object sender, EventArgs e)
  277. {
  278. panel1.Enabled = checkBox1.Checked;
  279. }
  280. private void radioButton2_CheckedChanged(object sender, EventArgs e)
  281. {
  282. btnCapTempl.Enabled = radioButton2.Checked;
  283. button1.Enabled = radioButton2.Checked;
  284. }
  285. }
  286. }