BinaryControl.cs 35 KB

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