BinaryControl.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. namespace PaintDotNet.CustomControl
  5. {
  6. public partial class BinaryControl : UserControl
  7. {
  8. /// <summary>
  9. /// 画笔
  10. /// </summary>
  11. private Pen pen = new Pen(Color.Red);
  12. public GroupBox groupBox6;
  13. public Button button4;
  14. public Label label2;
  15. public Panel panel2;
  16. private RadioButton radioButton2;
  17. private RadioButton radioButton1;
  18. public GroupBox groupBox9;
  19. public CheckBox checkBox10;
  20. private HistogramControl histogramControl1;
  21. public DecimalScopeControl numberScopeControl3;
  22. public DecimalScopeControl numberScopeControl2;
  23. private DecimalScopeControl numberScopeControl1;
  24. private CheckBox checkBox5;
  25. public Button button7;
  26. public Button button6;
  27. public double scope1Start
  28. {
  29. get
  30. {
  31. return this.numberScopeControl1.minValue;
  32. }
  33. set
  34. {
  35. this.numberScopeControl1.minValue = value;
  36. }
  37. }
  38. public double scope1End
  39. {
  40. get
  41. {
  42. return this.numberScopeControl1.maxValue;
  43. }
  44. set
  45. {
  46. this.numberScopeControl1.maxValue = value;
  47. }
  48. }
  49. public double scope2Start
  50. {
  51. get
  52. {
  53. return this.numberScopeControl2.minValue;
  54. }
  55. set
  56. {
  57. this.numberScopeControl2.minValue = value;
  58. }
  59. }
  60. public double scope2End
  61. {
  62. get
  63. {
  64. return this.numberScopeControl2.maxValue;
  65. }
  66. set
  67. {
  68. this.numberScopeControl2.maxValue = value;
  69. }
  70. }
  71. public double scope3Start
  72. {
  73. get
  74. {
  75. return this.numberScopeControl3.minValue;
  76. }
  77. set
  78. {
  79. this.numberScopeControl3.minValue = value;
  80. }
  81. }
  82. public double scope3End
  83. {
  84. get
  85. {
  86. return this.numberScopeControl3.maxValue;
  87. }
  88. set
  89. {
  90. this.numberScopeControl3.maxValue = value;
  91. }
  92. }
  93. /// <summary>
  94. /// 是否勾选了二值化
  95. /// </summary>
  96. /// <returns></returns>
  97. public bool BinaryChecked
  98. {
  99. get
  100. {
  101. return checkBox10.Checked;
  102. }
  103. set
  104. {
  105. checkBox10.Checked = value;
  106. }
  107. }
  108. /// <summary>
  109. /// 是否勾选了显示原图
  110. /// </summary>
  111. /// <returns></returns>
  112. public bool OriginChecked
  113. {
  114. get
  115. {
  116. return checkBox5.Checked;
  117. }
  118. set
  119. {
  120. checkBox5.Checked = value;
  121. }
  122. }
  123. /// <summary>
  124. /// 公开的事件,执行读取参数的事件
  125. /// </summary>
  126. public event EventHandler BinaryGetParamAction;
  127. private void OnBinaryGetParamAction(object sender, EventArgs e)
  128. {
  129. if (BinaryGetParamAction != null)
  130. {
  131. BinaryGetParamAction(sender, e);
  132. }
  133. }
  134. /// <summary>
  135. /// 公开的事件,执行二值方法的事件
  136. /// </summary>
  137. public event EventHandler ApplyButtonImplAction;
  138. private void OnApplyButtonImplAction(object sender, EventArgs e)
  139. {
  140. if (ApplyButtonImplAction != null)
  141. {
  142. ApplyButtonImplAction(sender, e);
  143. }
  144. }
  145. /// <summary>
  146. /// 公开的事件,筛选按钮点击的事件
  147. /// </summary>
  148. public event EventHandler BinaryEditClickAction;
  149. private void OnBinaryEditClickAction()
  150. {
  151. if (BinaryEditClickAction != null)
  152. {
  153. BinaryEditClickAction(this, new EventArgs());
  154. }
  155. }
  156. /// <summary>
  157. /// 公开的事件,相颜色点击的事件
  158. /// </summary>
  159. public event EventHandler PanelColorClickAction;
  160. private void OnPanelColorClickAction()
  161. {
  162. if (PanelColorClickAction != null)//###20143
  163. {
  164. PanelColorClickAction(this, new EventArgs());
  165. }
  166. }
  167. /// <summary>
  168. /// 公开的事件
  169. /// </summary>
  170. public event EventHandler RadioButton1ChangedAction;
  171. private void OnRadioButton1ChangedAction()
  172. {
  173. if (RadioButton1ChangedAction != null)
  174. {
  175. RadioButton1ChangedAction(this, new EventArgs());
  176. }
  177. }
  178. public event EventHandler RadioButton2ChangedAction;
  179. private void OnRadioButton2ChangedAction()
  180. {
  181. if (RadioButton2ChangedAction != null)
  182. {
  183. RadioButton2ChangedAction(this, new EventArgs());
  184. }
  185. }
  186. public event EventHandler OriginCheckedChangedAction;
  187. private void OnOriginCheckedChangedAction()
  188. {
  189. if (OriginCheckedChangedAction != null)
  190. {
  191. OriginCheckedChangedAction(this, new EventArgs());
  192. }
  193. }
  194. public event EventHandler BinaryCheckedChangedAction;
  195. private void OnBinaryCheckedChangedAction()
  196. {
  197. if (BinaryCheckedChangedAction != null)
  198. {
  199. BinaryCheckedChangedAction(this, new EventArgs());
  200. }
  201. }
  202. public event EventHandler ScopeValue1ChangedAction;
  203. private void OnScopeValue1ChangedAction(object sender, EventArgs e)
  204. {
  205. if (ScopeValue1ChangedAction != null)
  206. {
  207. ScopeValue1ChangedAction(sender, e);
  208. }
  209. }
  210. public event EventHandler ScopeValue2ChangedAction;
  211. private void OnScopeValue2ChangedAction(object sender, EventArgs e)
  212. {
  213. if (ScopeValue2ChangedAction != null)
  214. {
  215. ScopeValue2ChangedAction(sender, e);
  216. }
  217. }
  218. public event EventHandler ScopeValue3ChangedAction;
  219. private void OnScopeValue3ChangedAction(object sender, EventArgs e)
  220. {
  221. if (ScopeValue3ChangedAction != null)
  222. {
  223. ScopeValue3ChangedAction(sender, e);
  224. }
  225. }
  226. /// <summary>
  227. /// 公开的事件,自动阈值按钮点击的事件
  228. /// </summary>
  229. public event EventHandler AutoThresClickAction;
  230. private void OnAutoThresClickAction()
  231. {
  232. if (AutoThresClickAction != null)
  233. {
  234. AutoThresClickAction(this, new EventArgs());
  235. }
  236. }
  237. public Color BinaryBackColor
  238. {
  239. get
  240. {
  241. return panel2.BackColor;
  242. }
  243. set
  244. {
  245. panel2.BackColor = value;
  246. }
  247. }
  248. public int BinaryStyle
  249. {
  250. get
  251. {
  252. return radioButton1.Checked ? 1 : 2;
  253. }
  254. set
  255. {
  256. if (value == 1) this.radioButton1.Checked = true;
  257. else if (value == 2) this.radioButton2.Checked = true;
  258. }
  259. }
  260. /// <summary>
  261. /// 公开的事件,反选按钮点击的事件
  262. /// </summary>
  263. public event EventHandler InverseClickAction;
  264. public int getInverseStyle()
  265. {
  266. return numberScopeControl2.Visible ? 2 : 1;
  267. }
  268. public void setInverseStyle(int style)
  269. {
  270. if (style == 1)
  271. {
  272. //隐藏控件
  273. this.numberScopeControl2.Visible = false;
  274. this.numberScopeControl3.Visible = false;
  275. this.button6.Text = PdnResources.GetString("Menu.inverse.text");
  276. }
  277. else if (style == 2)
  278. {
  279. this.numberScopeControl2.Visible = true;
  280. this.numberScopeControl3.Visible = true;
  281. this.button6.Text = PdnResources.GetString("Menu.Uncheck.text");
  282. }
  283. }
  284. public void OnInverseClickAction()
  285. {
  286. if (numberScopeControl2.Visible)
  287. {
  288. this.numberScopeControl1.minValue = this.numberScopeControl3.maxValue;
  289. this.numberScopeControl1.maxValue = this.numberScopeControl2.minValue;
  290. this.numberScopeControl2.Visible = false;
  291. this.numberScopeControl3.Visible = false;
  292. this.button6.Text = PdnResources.GetString("Menu.inverse.text");
  293. this.histogramControl1.Flag = 1;
  294. this.histogramControl1.UpdateVerticalBarWithOneScope((int)(this.numberScopeControl1.minValue), (int)(this.numberScopeControl1.maxValue));
  295. }
  296. else
  297. {
  298. this.numberScopeControl3.minValue = 0;
  299. this.numberScopeControl3.maxValue = this.numberScopeControl1.minValue;
  300. this.numberScopeControl2.minValue = this.numberScopeControl1.maxValue;
  301. this.numberScopeControl2.maxValue = 255;
  302. this.numberScopeControl2.Visible = true;
  303. this.numberScopeControl3.Visible = true;
  304. this.button6.Text = PdnResources.GetString("Menu.Uncheck.text");
  305. this.histogramControl1.Flag = 2;
  306. //处理直方图
  307. this.histogramControl1.UpdateVerticalBarWithTwoScope(
  308. (int)(this.numberScopeControl3.minValue),
  309. (int)(this.numberScopeControl3.maxValue),
  310. (int)(this.numberScopeControl2.minValue),
  311. (int)(this.numberScopeControl2.maxValue)
  312. );
  313. }
  314. if (InverseClickAction != null)
  315. {
  316. InverseClickAction(this, new EventArgs());
  317. }
  318. }
  319. /// <summary>
  320. /// 公开的事件,第一条线拖拽的事件
  321. /// </summary>
  322. public event EventHandler<EventArgs<int>> DragOneEventActionFinish;
  323. private void OnDragOneEventActionFinish(int start)
  324. {
  325. if (DragOneEventActionFinish != null)
  326. {
  327. DragOneEventActionFinish(this, new EventArgs<int>(start));
  328. }
  329. }
  330. public event EventHandler<EventArgs<int>> DragTwoEventActionFinish;
  331. private void OnDragTwoEventActionFinish(int end)
  332. {
  333. if (DragTwoEventActionFinish != null)
  334. {
  335. DragTwoEventActionFinish(this, new EventArgs<int>(end));
  336. }
  337. }
  338. public event EventHandler<EventArgs<int>> DragThreeEventActionFinish;
  339. private void OnDragThreeEventActionFinish(int start1)
  340. {
  341. if (DragThreeEventActionFinish != null)
  342. {
  343. DragThreeEventActionFinish(this, new EventArgs<int>(start1));
  344. }
  345. }
  346. public event EventHandler<EventArgs<int>> DragFourEventActionFinish;
  347. private void OnDragFourEventActionFinish(int start1)
  348. {
  349. if (DragFourEventActionFinish != null)
  350. {
  351. DragFourEventActionFinish(this, new EventArgs<int>(start1));
  352. }
  353. }
  354. public BinaryControl()
  355. {
  356. InitializeComponent();
  357. InitializeLanguageText();
  358. }
  359. private void InitializeLanguageText()
  360. {
  361. this.groupBox6.Text = PdnResources.GetString("Menu.Binarystyle.text");
  362. this.button4.Text = PdnResources.GetString("Menu.filter.text");
  363. this.label2.Text = PdnResources.GetString("Menu.Phasecolor.text") + ":";
  364. this.radioButton2.Text = PdnResources.GetString("Menu.Sideline.text");
  365. this.radioButton1.Text = PdnResources.GetString("Menu.solid.text");
  366. this.groupBox9.Text = PdnResources.GetString("Menu.Tools.Histogram.Text");
  367. this.checkBox10.Text = PdnResources.GetString("Menu.Binarization.text");
  368. this.checkBox5.Text = PdnResources.GetString("Menu.Theoriginalcolor.text");
  369. this.button7.Text = PdnResources.GetString("Menu.Automaticthreshold.text");
  370. this.button6.Text = PdnResources.GetString("Menu.inverse.text");
  371. }
  372. private void InitializeComponent()
  373. {
  374. this.groupBox6 = new System.Windows.Forms.GroupBox();
  375. this.button4 = new System.Windows.Forms.Button();
  376. this.label2 = new System.Windows.Forms.Label();
  377. this.panel2 = new System.Windows.Forms.Panel();
  378. this.radioButton2 = new System.Windows.Forms.RadioButton();
  379. this.radioButton1 = new System.Windows.Forms.RadioButton();
  380. this.groupBox9 = new System.Windows.Forms.GroupBox();
  381. this.checkBox10 = new System.Windows.Forms.CheckBox();
  382. this.checkBox5 = new System.Windows.Forms.CheckBox();
  383. this.button7 = new System.Windows.Forms.Button();
  384. this.button6 = new System.Windows.Forms.Button();
  385. this.histogramControl1 = new PaintDotNet.CustomControl.HistogramControl();
  386. this.numberScopeControl3 = new PaintDotNet.CustomControl.DecimalScopeControl();
  387. this.numberScopeControl2 = new PaintDotNet.CustomControl.DecimalScopeControl();
  388. this.numberScopeControl1 = new PaintDotNet.CustomControl.DecimalScopeControl();
  389. this.groupBox6.SuspendLayout();
  390. this.groupBox9.SuspendLayout();
  391. this.SuspendLayout();
  392. //
  393. // groupBox6
  394. //
  395. this.groupBox6.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  396. | System.Windows.Forms.AnchorStyles.Right)));
  397. this.groupBox6.Controls.Add(this.button4);
  398. this.groupBox6.Controls.Add(this.label2);
  399. this.groupBox6.Controls.Add(this.panel2);
  400. this.groupBox6.Controls.Add(this.radioButton2);
  401. this.groupBox6.Controls.Add(this.radioButton1);
  402. this.groupBox6.Location = new System.Drawing.Point(2, 226);
  403. this.groupBox6.Margin = new System.Windows.Forms.Padding(0);
  404. this.groupBox6.Name = "groupBox6";
  405. this.groupBox6.Size = new System.Drawing.Size(356, 64);
  406. this.groupBox6.TabIndex = 22;
  407. this.groupBox6.TabStop = false;
  408. this.groupBox6.Text = "二值样式";
  409. //
  410. // button4
  411. //
  412. this.button4.Anchor = System.Windows.Forms.AnchorStyles.Right;
  413. this.button4.Location = new System.Drawing.Point(259, 29);
  414. this.button4.Name = "button4";
  415. this.button4.Size = new System.Drawing.Size(75, 23);
  416. this.button4.TabIndex = 32;
  417. this.button4.Text = "筛选";
  418. this.button4.UseVisualStyleBackColor = true;
  419. this.button4.Click += new System.EventHandler(this.button4_Click);
  420. //
  421. // label2
  422. //
  423. this.label2.AutoSize = true;
  424. this.label2.Location = new System.Drawing.Point(132, 34);
  425. this.label2.Name = "label2";
  426. this.label2.Size = new System.Drawing.Size(47, 12);
  427. this.label2.TabIndex = 20;
  428. this.label2.Text = "相颜色:";
  429. //
  430. // panel2
  431. //
  432. this.panel2.BackColor = System.Drawing.Color.Red;
  433. this.panel2.Location = new System.Drawing.Point(182, 29);
  434. this.panel2.Name = "panel2";
  435. this.panel2.Size = new System.Drawing.Size(72, 21);
  436. this.panel2.TabIndex = 19;
  437. this.panel2.Click += new System.EventHandler(this.panel2_Click);
  438. //
  439. // radioButton2
  440. //
  441. this.radioButton2.AutoSize = true;
  442. this.radioButton2.Location = new System.Drawing.Point(59, 32);
  443. this.radioButton2.Name = "radioButton2";
  444. this.radioButton2.Size = new System.Drawing.Size(47, 16);
  445. this.radioButton2.TabIndex = 1;
  446. this.radioButton2.Text = "边线";
  447. this.radioButton2.UseVisualStyleBackColor = true;
  448. this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged);
  449. //
  450. // radioButton1
  451. //
  452. this.radioButton1.AutoSize = true;
  453. this.radioButton1.Checked = true;
  454. this.radioButton1.Location = new System.Drawing.Point(7, 32);
  455. this.radioButton1.Name = "radioButton1";
  456. this.radioButton1.Size = new System.Drawing.Size(47, 16);
  457. this.radioButton1.TabIndex = 0;
  458. this.radioButton1.TabStop = true;
  459. this.radioButton1.Text = "实心";
  460. this.radioButton1.UseVisualStyleBackColor = true;
  461. this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
  462. //
  463. // groupBox9
  464. //
  465. this.groupBox9.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  466. | System.Windows.Forms.AnchorStyles.Right)));
  467. this.groupBox9.Controls.Add(this.checkBox10);
  468. this.groupBox9.Controls.Add(this.histogramControl1);
  469. this.groupBox9.Controls.Add(this.numberScopeControl3);
  470. this.groupBox9.Controls.Add(this.numberScopeControl2);
  471. this.groupBox9.Controls.Add(this.numberScopeControl1);
  472. this.groupBox9.Controls.Add(this.checkBox5);
  473. this.groupBox9.Controls.Add(this.button7);
  474. this.groupBox9.Controls.Add(this.button6);
  475. this.groupBox9.Location = new System.Drawing.Point(2, 2);
  476. this.groupBox9.Margin = new System.Windows.Forms.Padding(0);
  477. this.groupBox9.Name = "groupBox9";
  478. this.groupBox9.Padding = new System.Windows.Forms.Padding(0);
  479. this.groupBox9.Size = new System.Drawing.Size(356, 218);
  480. this.groupBox9.TabIndex = 21;
  481. this.groupBox9.TabStop = false;
  482. this.groupBox9.Text = "直方图";
  483. //
  484. // checkBox10
  485. //
  486. this.checkBox10.Anchor = System.Windows.Forms.AnchorStyles.Right;
  487. this.checkBox10.AutoSize = true;
  488. this.checkBox10.Location = new System.Drawing.Point(208, 195);
  489. this.checkBox10.Name = "checkBox10";
  490. this.checkBox10.Size = new System.Drawing.Size(60, 16);
  491. this.checkBox10.TabIndex = 17;
  492. this.checkBox10.Text = "二值化";
  493. this.checkBox10.UseVisualStyleBackColor = true;
  494. this.checkBox10.CheckedChanged += new System.EventHandler(this.checkBox10_CheckedChanged);
  495. //
  496. // checkBox5
  497. //
  498. this.checkBox5.Anchor = System.Windows.Forms.AnchorStyles.Right;
  499. this.checkBox5.AutoSize = true;
  500. this.checkBox5.Location = new System.Drawing.Point(293, 195);
  501. this.checkBox5.Name = "checkBox5";
  502. this.checkBox5.Size = new System.Drawing.Size(48, 16);
  503. this.checkBox5.TabIndex = 11;
  504. this.checkBox5.Text = "原图";
  505. this.checkBox5.UseVisualStyleBackColor = true;
  506. this.checkBox5.CheckedChanged += new System.EventHandler(this.ShowOrHideOriginPic);
  507. //
  508. // button7
  509. //
  510. this.button7.Anchor = System.Windows.Forms.AnchorStyles.Left;
  511. this.button7.Location = new System.Drawing.Point(86, 191);
  512. this.button7.Name = "button7";
  513. this.button7.Size = new System.Drawing.Size(75, 23);
  514. this.button7.TabIndex = 12;
  515. this.button7.Text = "自动阈值";
  516. this.button7.UseVisualStyleBackColor = true;
  517. this.button7.Click += new System.EventHandler(this.button7_Click);
  518. //
  519. // button6
  520. //
  521. this.button6.Anchor = System.Windows.Forms.AnchorStyles.Left;
  522. this.button6.Location = new System.Drawing.Point(5, 191);
  523. this.button6.Name = "button6";
  524. this.button6.Size = new System.Drawing.Size(75, 23);
  525. this.button6.TabIndex = 11;
  526. this.button6.Text = "反选";
  527. this.button6.UseVisualStyleBackColor = true;
  528. this.button6.Click += new System.EventHandler(this.button6_Click);
  529. //
  530. // histogramControl1
  531. //
  532. this.histogramControl1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  533. | System.Windows.Forms.AnchorStyles.Right)));
  534. this.histogramControl1.Flag = 1;
  535. this.histogramControl1.Location = new System.Drawing.Point(5, 19);
  536. this.histogramControl1.Name = "histogramControl1";
  537. this.histogramControl1.Size = new System.Drawing.Size(340, 130);
  538. this.histogramControl1.TabIndex = 16;
  539. //
  540. // numberScopeControl3
  541. //
  542. this.numberScopeControl3.DecimalPlaces = 0;
  543. this.numberScopeControl3.Location = new System.Drawing.Point(8, 158);
  544. this.numberScopeControl3.Maximum = 255D;
  545. this.numberScopeControl3.maxValue = 0D;
  546. this.numberScopeControl3.Minimum = 0D;
  547. this.numberScopeControl3.minValue = 0D;
  548. this.numberScopeControl3.Name = "numberScopeControl3";
  549. this.numberScopeControl3.Size = new System.Drawing.Size(150, 22);
  550. this.numberScopeControl3.TabIndex = 15;
  551. this.numberScopeControl3.Visible = false;
  552. this.numberScopeControl3.ValueChanged += new System.EventHandler(this.OnScopeValue3ChangedAction);
  553. //
  554. // numberScopeControl2
  555. //
  556. this.numberScopeControl2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  557. this.numberScopeControl2.DecimalPlaces = 0;
  558. this.numberScopeControl2.Location = new System.Drawing.Point(189, 155);
  559. this.numberScopeControl2.Maximum = 255D;
  560. this.numberScopeControl2.maxValue = 0D;
  561. this.numberScopeControl2.Minimum = 0D;
  562. this.numberScopeControl2.minValue = 0D;
  563. this.numberScopeControl2.Name = "numberScopeControl2";
  564. this.numberScopeControl2.Size = new System.Drawing.Size(150, 22);
  565. this.numberScopeControl2.TabIndex = 14;
  566. this.numberScopeControl2.Visible = false;
  567. this.numberScopeControl2.ValueChanged += new System.EventHandler(this.OnScopeValue2ChangedAction);
  568. //
  569. // numberScopeControl1
  570. //
  571. this.numberScopeControl1.DecimalPlaces = 0;
  572. this.numberScopeControl1.Location = new System.Drawing.Point(8, 158);
  573. this.numberScopeControl1.Maximum = 255D;
  574. this.numberScopeControl1.maxValue = 0D;
  575. this.numberScopeControl1.Minimum = 0D;
  576. this.numberScopeControl1.minValue = 0D;
  577. this.numberScopeControl1.Name = "numberScopeControl1";
  578. this.numberScopeControl1.Size = new System.Drawing.Size(150, 22);
  579. this.numberScopeControl1.TabIndex = 13;
  580. this.numberScopeControl1.Tag = "numberScopeControl1";
  581. this.numberScopeControl1.ValueChanged += new System.EventHandler(this.OnScopeValue1ChangedAction);
  582. //
  583. // BinaryControl
  584. //
  585. this.Controls.Add(this.groupBox6);
  586. this.Controls.Add(this.groupBox9);
  587. this.Margin = new System.Windows.Forms.Padding(3, 3, 0, 3);
  588. this.Name = "BinaryControl";
  589. this.Size = new System.Drawing.Size(360, 292);
  590. this.groupBox6.ResumeLayout(false);
  591. this.groupBox6.PerformLayout();
  592. this.groupBox9.ResumeLayout(false);
  593. this.groupBox9.PerformLayout();
  594. this.ResumeLayout(false);
  595. }
  596. /// <summary>
  597. /// 筛选按钮
  598. /// </summary>
  599. /// <param name="sender"></param>
  600. /// <param name="e"></param>
  601. private void button4_Click(object sender, EventArgs e)
  602. {
  603. OnBinaryEditClickAction();
  604. }
  605. /// <summary>
  606. /// 相颜色点击事件
  607. /// </summary>
  608. /// <param name="sender"></param>
  609. /// <param name="e"></param>
  610. private void panel2_Click(object sender, EventArgs e)
  611. {
  612. OnPanelColorClickAction();
  613. }
  614. /// <summary>
  615. /// 二值样式 边线选中事件
  616. /// </summary>
  617. /// <param name="sender"></param>
  618. /// <param name="e"></param>
  619. private void radioButton2_CheckedChanged(object sender, EventArgs e)
  620. {
  621. OnRadioButton2ChangedAction();
  622. }
  623. /// <summary>
  624. /// 二值样式 实心选中事件
  625. /// </summary>
  626. /// <param name="sender"></param>
  627. /// <param name="e"></param>
  628. private void radioButton1_CheckedChanged(object sender, EventArgs e)
  629. {
  630. OnRadioButton1ChangedAction();
  631. }
  632. private void ShowOrHideOriginPic(object sender, EventArgs e)
  633. {
  634. OnOriginCheckedChangedAction();
  635. }
  636. private void checkBox10_CheckedChanged(object sender, EventArgs e)
  637. {
  638. OnBinaryCheckedChangedAction();
  639. }
  640. public void button7_Click(object sender, EventArgs e)
  641. {
  642. OnAutoThresClickAction();
  643. }
  644. public void button6_Click(object sender, EventArgs e)
  645. {
  646. OnInverseClickAction();
  647. }
  648. /// <summary>
  649. /// 把参数的值设置到控件上
  650. /// </summary>
  651. public void InitParameterToControl(int ColorInterval = -1)
  652. {
  653. if (ColorInterval != -1 ? ColorInterval == 1 : this.getInverseStyle() == 1)
  654. {
  655. //处理直方图
  656. this.histogramControl1.UpdateVerticalBarWithOneScope((int)(this.numberScopeControl1.minValue), (int)(this.numberScopeControl1.maxValue));
  657. }
  658. else
  659. {
  660. //处理直方图
  661. this.histogramControl1.UpdateVerticalBarWithTwoScope(
  662. (int)(this.numberScopeControl3.minValue),
  663. (int)(this.numberScopeControl3.maxValue),
  664. (int)(this.numberScopeControl2.minValue),
  665. (int)(this.numberScopeControl2.maxValue)
  666. );
  667. }
  668. }
  669. /// <summary>
  670. /// 颜色区间2 截止值变化
  671. /// </summary>
  672. /// <param name="sender"></param>
  673. /// <param name="e"></param>
  674. private void DragFourEvent(object sender, EventArgs<int> e)
  675. {
  676. this.numberScopeControl2.maxValue = e.Data;
  677. }
  678. /// <summary>
  679. /// 颜色区间2 起始值变化
  680. /// </summary>
  681. /// <param name="sender"></param>
  682. /// <param name="e"></param>
  683. private void DragThreeEvent(object sender, EventArgs<int> e)
  684. {
  685. this.numberScopeControl2.minValue = e.Data;
  686. }
  687. /// <summary>
  688. /// 颜色区间1 截止值变化
  689. /// </summary>
  690. /// <param name="sender"></param>
  691. /// <param name="e"></param>
  692. private void DragTwoEvent(object sender, EventArgs<int> e)
  693. {
  694. if (this.getInverseStyle() == 1)
  695. {
  696. this.numberScopeControl1.maxValue = e.Data;
  697. }
  698. else if (this.getInverseStyle() == 2)
  699. {
  700. this.numberScopeControl3.maxValue = e.Data;
  701. }
  702. }
  703. /// <summary>
  704. /// 颜色区间1 起始值变化
  705. /// </summary>
  706. /// <param name="sender"></param>
  707. /// <param name="e"></param>
  708. private void DragOneEvent(object sender, EventArgs<int> e)
  709. {
  710. if (this.getInverseStyle() == 1)
  711. {
  712. this.numberScopeControl1.minValue = e.Data;
  713. }
  714. else if (this.getInverseStyle() == 2)
  715. {
  716. this.numberScopeControl3.minValue = e.Data;
  717. }
  718. }
  719. private void DragFiveEvent(object sender, EventArgs<int[]> e)
  720. {
  721. DeleteEventHandler();
  722. if (this.getInverseStyle() == 1)
  723. {
  724. this.numberScopeControl1.minValue = e.Data[1];
  725. this.numberScopeControl1.maxValue = e.Data[0];
  726. }
  727. else if (this.getInverseStyle() == 2)
  728. {
  729. this.numberScopeControl3.minValue = e.Data[1];
  730. this.numberScopeControl3.maxValue = e.Data[0];
  731. }
  732. AddEventHandler();
  733. this.OnApplyButtonImplAction(null, null);
  734. }
  735. private void DragSixEvent(object sender, EventArgs<int[]> e)
  736. {
  737. DeleteEventHandler();
  738. this.numberScopeControl2.minValue = e.Data[1];
  739. this.numberScopeControl2.maxValue = e.Data[0];
  740. AddEventHandler();
  741. this.OnApplyButtonImplAction(null, null);
  742. }
  743. public void InitBinaryControlEvent()//InitHistogramDragEvent()
  744. {
  745. this.histogramControl1.DragOneEventActionFinish += new EventHandler<EventArgs<int>>(this.DragOneEvent);
  746. this.histogramControl1.DragTwoEventActionFinish += new EventHandler<EventArgs<int>>(this.DragTwoEvent);
  747. this.histogramControl1.DragThreeEventActionFinish += new EventHandler<EventArgs<int>>(this.DragThreeEvent);
  748. this.histogramControl1.DragFourEventActionFinish += new EventHandler<EventArgs<int>>(this.DragFourEvent);
  749. this.histogramControl1.DragFiveEventActionFinish += new EventHandler<EventArgs<int[]>>(this.DragFiveEvent);
  750. this.histogramControl1.DragSixEventActionFinish += new EventHandler<EventArgs<int[]>>(this.DragSixEvent);
  751. }
  752. public void AddEventHandler()
  753. {
  754. this.numberScopeControl1.ValueChanged += this.numberScope1_ValueChanged;
  755. this.numberScopeControl1.numericUpDown1.KeyUp += this.numberScope1_ValueChanged;
  756. this.numberScopeControl1.numericUpDown2.KeyUp += this.numberScope1_ValueChanged;
  757. this.numberScopeControl3.numericUpDown2.KeyUp += this.OnApplyButtonImplAction;//###
  758. this.numberScopeControl2.ValueChanged += this.numberScope2_ValueChanged;
  759. this.numberScopeControl2.numericUpDown1.KeyUp += this.numberScope2_ValueChanged;
  760. this.numberScopeControl2.numericUpDown2.KeyUp += this.numberScope2_ValueChanged;
  761. this.numberScopeControl3.ValueChanged += this.numberScope3_ValueChanged;
  762. this.numberScopeControl3.numericUpDown1.KeyUp += this.numberScope3_ValueChanged;
  763. this.numberScopeControl3.numericUpDown2.KeyUp += this.numberScope3_ValueChanged;
  764. this.numberScopeControl1.ValueChanged += this.OnApplyButtonImplAction;
  765. this.numberScopeControl2.ValueChanged += this.OnApplyButtonImplAction;
  766. this.numberScopeControl3.ValueChanged += this.OnApplyButtonImplAction;
  767. //this.panel2.BackColorChanged += this.OnApplyButtonImplAction;
  768. this.radioButton1.CheckedChanged += this.OnApplyButtonImplAction;
  769. this.radioButton2.CheckedChanged += this.OnApplyButtonImplAction;
  770. }
  771. public void DeleteEventHandler()
  772. {
  773. this.numberScopeControl1.ValueChanged -= this.numberScope1_ValueChanged;
  774. this.numberScopeControl1.numericUpDown1.KeyUp -= this.numberScope1_ValueChanged;
  775. this.numberScopeControl1.numericUpDown2.KeyUp -= this.numberScope1_ValueChanged;
  776. this.numberScopeControl3.numericUpDown2.KeyUp -= this.OnApplyButtonImplAction;//###
  777. this.numberScopeControl2.ValueChanged -= this.numberScope2_ValueChanged;
  778. this.numberScopeControl2.numericUpDown1.KeyUp -= this.numberScope2_ValueChanged;
  779. this.numberScopeControl2.numericUpDown2.KeyUp -= this.numberScope2_ValueChanged;
  780. this.numberScopeControl3.ValueChanged -= this.numberScope3_ValueChanged;
  781. this.numberScopeControl3.numericUpDown1.KeyUp -= this.numberScope3_ValueChanged;
  782. this.numberScopeControl3.numericUpDown2.KeyUp -= this.numberScope3_ValueChanged;
  783. this.numberScopeControl1.ValueChanged -= this.OnApplyButtonImplAction;
  784. this.numberScopeControl2.ValueChanged -= this.OnApplyButtonImplAction;
  785. this.numberScopeControl3.ValueChanged -= this.OnApplyButtonImplAction;
  786. //this.panel2.BackColorChanged -= this.OnApplyButtonImplAction;
  787. this.radioButton1.CheckedChanged -= this.OnApplyButtonImplAction;
  788. this.radioButton2.CheckedChanged -= this.OnApplyButtonImplAction;
  789. }
  790. //处理直方图
  791. public void UpdateVerticalBarWithOneScope(int start, int end)
  792. {
  793. this.histogramControl1.UpdateVerticalBarWithOneScope(start, end);
  794. }
  795. //绘制直方图
  796. public void CreateHistogram(OpenCvSharp.Mat imageMat, bool isGray, int width, int height, int channel)
  797. {
  798. this.histogramControl1.CreateHistogram(imageMat, isGray, width, height, channel);
  799. }
  800. /// <summary>
  801. /// 一个颜色区间时
  802. /// 区间值变化的事件
  803. /// </summary>
  804. /// <param name="sender"></param>
  805. /// <param name="e"></param>
  806. private void numberScope1_ValueChanged(object sender, EventArgs e)
  807. {
  808. this.OnBinaryGetParamAction(sender, e);
  809. //处理直方图
  810. this.histogramControl1.UpdateVerticalBarWithOneScope((int)(this.numberScopeControl1.minValue), (int)(this.numberScopeControl1.maxValue));
  811. }
  812. /// <summary>
  813. /// 二个颜色区间时
  814. /// 区间1值变化的事件
  815. /// </summary>
  816. /// <param name="sender"></param>
  817. /// <param name="e"></param>
  818. private void numberScope2_ValueChanged(object sender, EventArgs e)
  819. {
  820. this.OnBinaryGetParamAction(sender, e);
  821. //处理直方图
  822. this.histogramControl1.UpdateVerticalBarWithTwoScope(
  823. (int)(this.numberScopeControl3.minValue),
  824. (int)(this.numberScopeControl3.maxValue),
  825. (int)(this.numberScopeControl2.minValue),
  826. (int)(this.numberScopeControl2.maxValue)
  827. );
  828. }
  829. /// <summary>
  830. /// 二个颜色区间时
  831. /// 区间2值变化的事件
  832. /// </summary>
  833. /// <param name="sender"></param>
  834. /// <param name="e"></param>
  835. private void numberScope3_ValueChanged(object sender, EventArgs e)
  836. {
  837. this.OnBinaryGetParamAction(sender, e);
  838. //处理直方图
  839. this.histogramControl1.UpdateVerticalBarWithTwoScope(
  840. (int)(this.numberScopeControl3.minValue),
  841. (int)(this.numberScopeControl3.maxValue),
  842. (int)(this.numberScopeControl2.minValue),
  843. (int)(this.numberScopeControl2.maxValue)
  844. );
  845. }
  846. }
  847. }