BinaryControlSmaller.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using OpenCvSharp;
  5. namespace PaintDotNet.CustomControl
  6. {
  7. public partial class BinaryControlSmaller : UserControl
  8. {
  9. /// <summary>
  10. /// 画笔
  11. /// </summary>
  12. private Pen pen = new Pen(Color.Red);
  13. private GroupBox groupBox6;
  14. private Button button4;
  15. private Label label2;
  16. private Panel panel2;
  17. private RadioButton radioButton2;
  18. private RadioButton radioButton1;
  19. private 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 BinaryControlSmaller()
  366. {
  367. InitializeComponent();
  368. InitializeLanguageText();
  369. }
  370. private void InitializeLanguageText()
  371. {
  372. this.button7.Text = PdnResources.GetString("Menu.Automaticthreshold.text");
  373. this.checkBox5.Text = PdnResources.GetString("Menu.Theoriginalcolor.text");
  374. this.checkBox10.Text = PdnResources.GetString("Menu.Binarization.text");
  375. this.groupBox9.Text = PdnResources.GetString("Menu.Tools.Histogram.Text");
  376. this.radioButton1.Text = PdnResources.GetString("Menu.solid.text");
  377. this.radioButton2.Text = PdnResources.GetString("Menu.Sideline.text");
  378. this.label2.Text = PdnResources.GetString("Menu.Phasecolor.text") + ":";
  379. this.button4.Text = PdnResources.GetString("Menu.filter.text");
  380. this.groupBox6.Text = PdnResources.GetString("Menu.Binarystyle.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.Controls.Add(this.button4);
  407. this.groupBox6.Controls.Add(this.label2);
  408. this.groupBox6.Controls.Add(this.panel2);
  409. this.groupBox6.Controls.Add(this.radioButton2);
  410. this.groupBox6.Controls.Add(this.radioButton1);
  411. this.groupBox6.Location = new System.Drawing.Point(2, 205);
  412. this.groupBox6.Name = "groupBox6";
  413. this.groupBox6.Size = new System.Drawing.Size(356, 40);
  414. this.groupBox6.TabIndex = 22;
  415. this.groupBox6.TabStop = false;
  416. this.groupBox6.Text = "二值样式";
  417. //
  418. // button4
  419. //
  420. this.button4.Anchor = System.Windows.Forms.AnchorStyles.Right;
  421. this.button4.Location = new System.Drawing.Point(259, 14);
  422. this.button4.Name = "button4";
  423. this.button4.Size = new System.Drawing.Size(75, 23);
  424. this.button4.TabIndex = 32;
  425. this.button4.Text = "筛选";
  426. this.button4.UseVisualStyleBackColor = true;
  427. this.button4.Click += new System.EventHandler(this.button4_Click);
  428. //
  429. // label2
  430. //
  431. this.label2.AutoSize = true;
  432. this.label2.Location = new System.Drawing.Point(131, 19);
  433. this.label2.Name = "label2";
  434. this.label2.Size = new System.Drawing.Size(47, 12);
  435. this.label2.TabIndex = 20;
  436. this.label2.Text = "相颜色:";
  437. //
  438. // panel2
  439. //
  440. this.panel2.BackColor = System.Drawing.Color.Red;
  441. this.panel2.Location = new System.Drawing.Point(181, 14);
  442. this.panel2.Name = "panel2";
  443. this.panel2.Size = new System.Drawing.Size(72, 21);
  444. this.panel2.TabIndex = 19;
  445. this.panel2.Click += new System.EventHandler(this.panel2_Click);
  446. //
  447. // radioButton2
  448. //
  449. this.radioButton2.AutoSize = true;
  450. this.radioButton2.Location = new System.Drawing.Point(58, 17);
  451. this.radioButton2.Name = "radioButton2";
  452. this.radioButton2.Size = new System.Drawing.Size(47, 16);
  453. this.radioButton2.TabIndex = 1;
  454. this.radioButton2.Text = "边线";
  455. this.radioButton2.UseVisualStyleBackColor = true;
  456. this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged);
  457. //
  458. // radioButton1
  459. //
  460. this.radioButton1.AutoSize = true;
  461. this.radioButton1.Checked = true;
  462. this.radioButton1.Location = new System.Drawing.Point(7, 17);
  463. this.radioButton1.Name = "radioButton1";
  464. this.radioButton1.Size = new System.Drawing.Size(47, 16);
  465. this.radioButton1.TabIndex = 0;
  466. this.radioButton1.TabStop = true;
  467. this.radioButton1.Text = "实心";
  468. this.radioButton1.UseVisualStyleBackColor = true;
  469. this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
  470. //
  471. // groupBox9
  472. //
  473. this.groupBox9.Controls.Add(this.checkBox10);
  474. this.groupBox9.Controls.Add(this.histogramControl1);
  475. this.groupBox9.Controls.Add(this.numberScopeControl3);
  476. this.groupBox9.Controls.Add(this.numberScopeControl2);
  477. this.groupBox9.Controls.Add(this.numberScopeControl1);
  478. this.groupBox9.Controls.Add(this.checkBox5);
  479. this.groupBox9.Controls.Add(this.button7);
  480. this.groupBox9.Controls.Add(this.button6);
  481. this.groupBox9.Location = new System.Drawing.Point(2, 2);
  482. this.groupBox9.Name = "groupBox9";
  483. this.groupBox9.Size = new System.Drawing.Size(356, 203);
  484. this.groupBox9.TabIndex = 21;
  485. this.groupBox9.TabStop = false;
  486. this.groupBox9.Text = "直方图";
  487. //
  488. // checkBox10
  489. //
  490. this.checkBox10.Anchor = System.Windows.Forms.AnchorStyles.Right;
  491. this.checkBox10.AutoSize = true;
  492. this.checkBox10.Location = new System.Drawing.Point(234, 181);
  493. this.checkBox10.Name = "checkBox10";
  494. this.checkBox10.Size = new System.Drawing.Size(60, 16);
  495. this.checkBox10.TabIndex = 17;
  496. this.checkBox10.Text = "二值化";
  497. this.checkBox10.UseVisualStyleBackColor = true;
  498. this.checkBox10.CheckedChanged += new System.EventHandler(this.checkBox10_CheckedChanged);
  499. //
  500. // checkBox5
  501. //
  502. this.checkBox5.Anchor = System.Windows.Forms.AnchorStyles.Right;
  503. this.checkBox5.AutoSize = true;
  504. this.checkBox5.Location = new System.Drawing.Point(300, 181);
  505. this.checkBox5.Name = "checkBox5";
  506. this.checkBox5.Size = new System.Drawing.Size(48, 16);
  507. this.checkBox5.TabIndex = 11;
  508. this.checkBox5.Text = "原图";
  509. this.checkBox5.UseVisualStyleBackColor = true;
  510. this.checkBox5.CheckedChanged += new System.EventHandler(this.ShowOrHideOriginPic);
  511. //
  512. // button7
  513. //
  514. this.button7.Anchor = System.Windows.Forms.AnchorStyles.Right;
  515. this.button7.Location = new System.Drawing.Point(109, 177);
  516. this.button7.Name = "button7";
  517. this.button7.Size = new System.Drawing.Size(75, 23);
  518. this.button7.TabIndex = 12;
  519. this.button7.Text = "自动阈值";
  520. this.button7.UseVisualStyleBackColor = true;
  521. this.button7.Click += new System.EventHandler(this.button7_Click);
  522. //
  523. // button6
  524. //
  525. this.button6.Anchor = System.Windows.Forms.AnchorStyles.Right;
  526. this.button6.Location = new System.Drawing.Point(8, 177);
  527. this.button6.Name = "button6";
  528. this.button6.Size = new System.Drawing.Size(75, 23);
  529. this.button6.TabIndex = 11;
  530. this.button6.Text = "反选";
  531. this.button6.UseVisualStyleBackColor = true;
  532. this.button6.Click += new System.EventHandler(this.button6_Click);
  533. //
  534. // histogramControl1
  535. //
  536. this.histogramControl1.Flag = 1;
  537. this.histogramControl1.Location = new System.Drawing.Point(8, 22);
  538. this.histogramControl1.Name = "histogramControl1";
  539. this.histogramControl1.Size = new System.Drawing.Size(340, 130);
  540. this.histogramControl1.TabIndex = 16;
  541. //
  542. // numberScopeControl3
  543. //
  544. this.numberScopeControl3.DecimalPlaces = 0;
  545. this.numberScopeControl3.Location = new System.Drawing.Point(8, 154);
  546. this.numberScopeControl3.Maximum = 255D;
  547. this.numberScopeControl3.maxValue = 0D;
  548. this.numberScopeControl3.Minimum = 0D;
  549. this.numberScopeControl3.minValue = 0D;
  550. this.numberScopeControl3.Name = "numberScopeControl3";
  551. this.numberScopeControl3.Size = new System.Drawing.Size(150, 22);
  552. this.numberScopeControl3.TabIndex = 15;
  553. this.numberScopeControl3.Visible = false;
  554. this.numberScopeControl3.ValueChanged += new System.EventHandler(this.OnScopeValue3ChangedAction);
  555. //
  556. // numberScopeControl2
  557. //
  558. this.numberScopeControl2.DecimalPlaces = 0;
  559. this.numberScopeControl2.Location = new System.Drawing.Point(186, 154);
  560. this.numberScopeControl2.Maximum = 255D;
  561. this.numberScopeControl2.maxValue = 0D;
  562. this.numberScopeControl2.Minimum = 0D;
  563. this.numberScopeControl2.minValue = 0D;
  564. this.numberScopeControl2.Name = "numberScopeControl2";
  565. this.numberScopeControl2.Size = new System.Drawing.Size(150, 22);
  566. this.numberScopeControl2.TabIndex = 14;
  567. this.numberScopeControl2.Visible = false;
  568. this.numberScopeControl2.ValueChanged += new System.EventHandler(this.OnScopeValue2ChangedAction);
  569. //
  570. // numberScopeControl1
  571. //
  572. this.numberScopeControl1.DecimalPlaces = 0;
  573. this.numberScopeControl1.Location = new System.Drawing.Point(8, 154);
  574. this.numberScopeControl1.Maximum = 255D;
  575. this.numberScopeControl1.maxValue = 0D;
  576. this.numberScopeControl1.Minimum = 0D;
  577. this.numberScopeControl1.minValue = 0D;
  578. this.numberScopeControl1.Name = "numberScopeControl1";
  579. this.numberScopeControl1.Size = new System.Drawing.Size(150, 22);
  580. this.numberScopeControl1.TabIndex = 13;
  581. this.numberScopeControl1.Tag = "numberScopeControl1";
  582. this.numberScopeControl1.ValueChanged += new System.EventHandler(this.OnScopeValue1ChangedAction);
  583. //
  584. // BinaryControlSmaller
  585. //
  586. this.Controls.Add(this.groupBox6);
  587. this.Controls.Add(this.groupBox9);
  588. this.Name = "BinaryControlSmaller";
  589. this.Size = new System.Drawing.Size(360, 247);
  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. private void button7_Click(object sender, EventArgs e)
  641. {
  642. OnAutoThresClickAction();
  643. }
  644. private 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(Bitmap bitmap, bool isGray, int width, int height, int channel)
  797. {
  798. this.histogramControl1.CreateHistogram(bitmap, 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. }