ScratchTreatmentDialog.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. using OpenCvSharp;
  2. using PaintDotNet.Annotation.Enum;
  3. using PaintDotNet.CustomControl;
  4. using PaintDotNet.Data.Param;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Drawing;
  8. using System.Windows.Forms;
  9. namespace PaintDotNet.Instrument
  10. {
  11. /// <summary>
  12. /// 工具-划痕处理
  13. /// </summary>
  14. internal partial class ScratchTreatmentDialog : FloatingToolForm/*PdnBaseForm*/
  15. {
  16. /// <summary>
  17. /// 主工作空间
  18. /// </summary>
  19. private AppWorkspace AppWorkspace;
  20. /// <summary>
  21. /// 当前处理的程序
  22. /// </summary>
  23. private ParamObject action;
  24. /// <summary>
  25. /// 原图片备份
  26. /// </summary>
  27. private Mat oldmat;
  28. /// <summary>
  29. /// 实现撤销的功能,将直线线宽、起点X Y、终点X Y的集合放入一个List
  30. /// </summary>
  31. private List<int[]> OperationsList = new List<int[]>();
  32. #region 控件相关
  33. private Button button3;
  34. private Button button4;
  35. private Button button5;
  36. /// <summary>
  37. /// 操作区控件
  38. /// </summary>
  39. private GroupBox groupBox1;
  40. private GroupBox groupBox2;
  41. private Label label1;
  42. private Label label2;
  43. private RadioButton checkBox1;
  44. private RadioButton checkBox2;
  45. private RadioButton checkBox3;
  46. private RadioButton checkBox4;
  47. private UserTextBox textBox1;//痕宽:只能输入数字
  48. private CustomControl.SelectButton s12Button;
  49. private CustomControl.SelectButton s9Button;
  50. private CustomControl.SelectButton s6Button;
  51. private CustomControl.SelectButton logButton;
  52. private List<SelectButton> listButton = new List<SelectButton>();
  53. private void InitializeLanguageText()
  54. {
  55. this.button3.Text = PdnResources.GetString("Menu.application.text");
  56. this.button4.Text = PdnResources.GetString("Menu.ensure.text");
  57. this.button5.Text = "撤销";// PdnResources.GetString("Menu.cancel.text");
  58. this.button5.Enabled = false;
  59. this.label1.Text = PdnResources.GetString("Menu.tool.Stainprocessing.Shapesettings.text") + ":";
  60. this.label2.Text = PdnResources.GetString("Menu.tool.scratching.Tracewidth.text") + ":";
  61. this.checkBox1.Text = PdnResources.GetString("Menu.LabelAction.DrawRectangle.Text");
  62. this.checkBox2.Text = PdnResources.GetString("Menu.LabelAction.DrawPolygon.Text");
  63. this.checkBox3.Text = PdnResources.GetString("Menu.circular.Text");
  64. this.checkBox4.Text = PdnResources.GetString("Menu.LabelAction.DrawEllipse.Text");
  65. this.listButton.Add(this.s12Button);
  66. this.listButton.Add(this.s9Button);
  67. this.listButton.Add(this.s6Button);
  68. this.listButton.Add(this.logButton);
  69. }
  70. private void InitializeComponent()
  71. {
  72. this.groupBox2 = new System.Windows.Forms.GroupBox();
  73. this.label2 = new System.Windows.Forms.Label();
  74. this.logButton = new PaintDotNet.CustomControl.SelectButton();
  75. this.s6Button = new PaintDotNet.CustomControl.SelectButton();
  76. this.s9Button = new PaintDotNet.CustomControl.SelectButton();
  77. this.s12Button = new PaintDotNet.CustomControl.SelectButton();
  78. this.textBox1 = new PaintDotNet.CustomControl.UserTextBox();
  79. this.button3 = new System.Windows.Forms.Button();
  80. this.button4 = new System.Windows.Forms.Button();
  81. this.button5 = new System.Windows.Forms.Button();
  82. this.label1 = new System.Windows.Forms.Label();
  83. this.checkBox1 = new System.Windows.Forms.RadioButton();
  84. this.checkBox2 = new System.Windows.Forms.RadioButton();
  85. this.checkBox3 = new System.Windows.Forms.RadioButton();
  86. this.checkBox4 = new System.Windows.Forms.RadioButton();
  87. this.groupBox2.SuspendLayout();
  88. this.SuspendLayout();
  89. //
  90. // groupBox2
  91. //
  92. this.groupBox2.Controls.Add(this.label2);
  93. this.groupBox2.Controls.Add(this.logButton);
  94. this.groupBox2.Controls.Add(this.s6Button);
  95. this.groupBox2.Controls.Add(this.s9Button);
  96. this.groupBox2.Controls.Add(this.s12Button);
  97. this.groupBox2.Controls.Add(this.textBox1);
  98. this.groupBox2.Location = new System.Drawing.Point(12, 6);
  99. this.groupBox2.Name = "groupBox2";
  100. this.groupBox2.Size = new System.Drawing.Size(271, 80);
  101. this.groupBox2.TabIndex = 4;
  102. this.groupBox2.TabStop = false;
  103. //
  104. // label2
  105. //
  106. this.label2.AutoSize = true;
  107. this.label2.Location = new System.Drawing.Point(5, 24);
  108. this.label2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
  109. this.label2.Name = "label2";
  110. this.label2.Size = new System.Drawing.Size(41, 12);
  111. this.label2.TabIndex = 10;
  112. this.label2.Text = "痕宽:";
  113. //
  114. // logButton
  115. //
  116. this.logButton.BackColor = System.Drawing.SystemColors.ControlDark;
  117. this.logButton.BtnSelect = false;
  118. this.logButton.BtnText = "3";
  119. this.logButton.Location = new System.Drawing.Point(54, 50);
  120. this.logButton.Name = "logButton";
  121. this.logButton.Size = new System.Drawing.Size(31, 21);
  122. this.logButton.TabIndex = 21;
  123. this.logButton.Click += new System.EventHandler(this.skipButton_Click);
  124. //
  125. // s6Button
  126. //
  127. this.s6Button.BackColor = System.Drawing.SystemColors.ControlDark;
  128. this.s6Button.BtnSelect = false;
  129. this.s6Button.BtnText = "6";
  130. this.s6Button.Location = new System.Drawing.Point(110, 50);
  131. this.s6Button.Name = "s6Button";
  132. this.s6Button.Size = new System.Drawing.Size(31, 21);
  133. this.s6Button.TabIndex = 20;
  134. this.s6Button.Click += new System.EventHandler(this.skipButton_Click);
  135. //
  136. // s9Button
  137. //
  138. this.s9Button.BackColor = System.Drawing.SystemColors.ControlDark;
  139. this.s9Button.BtnSelect = false;
  140. this.s9Button.BtnText = "9";
  141. this.s9Button.Location = new System.Drawing.Point(166, 50);
  142. this.s9Button.Name = "s9Button";
  143. this.s9Button.Size = new System.Drawing.Size(31, 21);
  144. this.s9Button.TabIndex = 30;
  145. this.s9Button.Click += new System.EventHandler(this.skipButton_Click);
  146. //
  147. // s12Button
  148. //
  149. this.s12Button.BackColor = System.Drawing.SystemColors.ControlDark;
  150. this.s12Button.BtnSelect = false;
  151. this.s12Button.BtnText = "12";
  152. this.s12Button.Location = new System.Drawing.Point(222, 50);
  153. this.s12Button.Name = "s12Button";
  154. this.s12Button.Size = new System.Drawing.Size(31, 21);
  155. this.s12Button.TabIndex = 31;
  156. this.s12Button.Click += new System.EventHandler(this.skipButton_Click);
  157. //
  158. // textBox1
  159. //
  160. this.textBox1.Location = new System.Drawing.Point(54, 18);
  161. this.textBox1.Name = "textBox1";
  162. this.textBox1.Size = new System.Drawing.Size(199, 21);
  163. this.textBox1.TabIndex = 4;
  164. //
  165. // button3
  166. //
  167. this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  168. this.button3.Location = new System.Drawing.Point(210, 108);
  169. this.button3.Name = "button3";
  170. this.button3.Size = new System.Drawing.Size(65, 23);
  171. this.button3.TabIndex = 5;
  172. this.button3.Text = "应用";
  173. this.button3.UseVisualStyleBackColor = true;
  174. this.button3.Click += new System.EventHandler(this.button3_Click);
  175. //
  176. // button4
  177. //
  178. this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  179. this.button4.Location = new System.Drawing.Point(70, 108);
  180. this.button4.Name = "button4";
  181. this.button4.Size = new System.Drawing.Size(65, 23);
  182. this.button4.TabIndex = 6;
  183. this.button4.Text = "确定";
  184. this.button4.UseVisualStyleBackColor = true;
  185. this.button4.Click += new System.EventHandler(this.button4_Click);
  186. //
  187. // button5
  188. //
  189. this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
  190. this.button5.Location = new System.Drawing.Point(140, 108);
  191. this.button5.Name = "button5";
  192. this.button5.Size = new System.Drawing.Size(65, 23);
  193. this.button5.TabIndex = 7;
  194. this.button5.Text = "撤销";
  195. this.button5.UseVisualStyleBackColor = true;
  196. this.button5.Click += new System.EventHandler(this.button5_Click);
  197. //
  198. // label1
  199. //
  200. this.label1.AutoSize = true;
  201. this.label1.Location = new System.Drawing.Point(12, 18);
  202. this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
  203. this.label1.Name = "label1";
  204. this.label1.Size = new System.Drawing.Size(82, 15);
  205. this.label1.TabIndex = 9;
  206. //
  207. // checkBox1
  208. //
  209. this.checkBox1.Anchor = System.Windows.Forms.AnchorStyles.Left;
  210. this.checkBox1.AutoSize = true;
  211. this.checkBox1.Checked = true;
  212. this.checkBox1.Location = new System.Drawing.Point(84, 17);
  213. this.checkBox1.Name = "checkBox1";
  214. this.checkBox1.Size = new System.Drawing.Size(72, 16);
  215. this.checkBox1.TabIndex = 5;
  216. this.checkBox1.TabStop = true;
  217. this.checkBox1.UseVisualStyleBackColor = true;
  218. //
  219. // checkBox2
  220. //
  221. this.checkBox2.Anchor = System.Windows.Forms.AnchorStyles.Left;
  222. this.checkBox2.AutoSize = true;
  223. this.checkBox2.Location = new System.Drawing.Point(180, 17);
  224. this.checkBox2.Name = "checkBox2";
  225. this.checkBox2.Size = new System.Drawing.Size(72, 16);
  226. this.checkBox2.TabIndex = 16;
  227. this.checkBox2.UseVisualStyleBackColor = true;
  228. //
  229. // checkBox3
  230. //
  231. this.checkBox3.Anchor = System.Windows.Forms.AnchorStyles.Left;
  232. this.checkBox3.AutoSize = true;
  233. this.checkBox3.Location = new System.Drawing.Point(84, 51);
  234. this.checkBox3.Name = "checkBox3";
  235. this.checkBox3.Size = new System.Drawing.Size(72, 16);
  236. this.checkBox3.TabIndex = 17;
  237. this.checkBox3.UseVisualStyleBackColor = true;
  238. //
  239. // checkBox4
  240. //
  241. this.checkBox4.Anchor = System.Windows.Forms.AnchorStyles.Left;
  242. this.checkBox4.AutoSize = true;
  243. this.checkBox4.Location = new System.Drawing.Point(180, 51);
  244. this.checkBox4.Name = "checkBox4";
  245. this.checkBox4.Size = new System.Drawing.Size(72, 16);
  246. this.checkBox4.TabIndex = 18;
  247. this.checkBox4.UseVisualStyleBackColor = true;
  248. //
  249. // ScratchTreatmentDialog
  250. //
  251. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  252. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  253. this.ClientSize = new System.Drawing.Size(295, 144);
  254. this.Controls.Add(this.groupBox2);
  255. this.Controls.Add(this.button5);
  256. this.Controls.Add(this.button4);
  257. this.Controls.Add(this.button3);
  258. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  259. this.Location = new System.Drawing.Point(0, 0);
  260. this.Margin = new System.Windows.Forms.Padding(6);
  261. this.Name = "ScratchTreatmentDialog";
  262. this.Text = "划痕处理";
  263. this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ScratchTreatmentDialog_FormClosing);
  264. this.Controls.SetChildIndex(this.button3, 0);
  265. this.Controls.SetChildIndex(this.button4, 0);
  266. this.Controls.SetChildIndex(this.button5, 0);
  267. this.Controls.SetChildIndex(this.groupBox2, 0);
  268. this.groupBox2.ResumeLayout(false);
  269. this.groupBox2.PerformLayout();
  270. this.ResumeLayout(false);
  271. }
  272. #endregion
  273. public ScratchTreatmentDialog(AppWorkspace AppWorkspace)
  274. {
  275. this.AppWorkspace = AppWorkspace;
  276. this.ShowInTaskbar = false;
  277. InitializeComponent();
  278. InitializeLanguageText();
  279. this.Text = PdnResources.GetString("Menu.Tools.ScratchTreatment.Text");/*;//待修改中文资源-scc备注 20200709*/
  280. action = new Data.Action.Action1214();
  281. this.AppWorkspace.ActiveDocumentWorkspaceChanging += new EventHandler(AppWorkspace_ActiveDocumentWorkspaceChanging);
  282. this.AppWorkspace.ActiveDocumentWorkspaceChanged += new EventHandler(this.ActiveDocumentWorkspaceChanged);
  283. this.VisibleChanged += new EventHandler(this.ScratchTreatmentDialog_FormClosed);
  284. }
  285. private void ScratchTreatmentDialog_FormClosed(object sender, EventArgs/*FormClosedEventArgs*/ e)
  286. {
  287. if (this.Visible)
  288. return;
  289. if (AppWorkspace.ActiveDocumentWorkspace != null)
  290. {
  291. AppWorkspace.ActiveDocumentWorkspace.GraphicsList.DeleteDrawClass(DrawToolType.DrawScratchTreatmentLine);
  292. if (AppWorkspace.ActiveDocumentWorkspace.AppWorkspace != null)
  293. AppWorkspace.ActiveDocumentWorkspace.AppWorkspace.RefreshLabelListDialog();
  294. AppWorkspace.ActiveDocumentWorkspace.Refresh();
  295. }
  296. if (AppWorkspace.ActiveDocumentWorkspace != null)
  297. {
  298. AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.Pointer;
  299. }
  300. }
  301. private void ActiveDocumentWorkspaceChanged(object sender, EventArgs e)
  302. {
  303. if (!this.Visible)
  304. return;
  305. if (this.AppWorkspace.ActiveDocumentWorkspace != null)
  306. {
  307. AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.DrawScratchTreatmentLine;
  308. }
  309. //this.PhaseModelsBackUp = this.AppWorkspace.ActiveDocumentWorkspace.PhaseModelsForCopy;
  310. }
  311. /// <summary>
  312. /// 图片切换的处理方法 //#20193
  313. /// </summary>
  314. /// <param name="sender"></param>
  315. /// <param name="e"></param>
  316. private void AppWorkspace_ActiveDocumentWorkspaceChanging(object sender, EventArgs e)
  317. {
  318. if (!this.Visible)
  319. return;
  320. if (oldmat != null)
  321. {
  322. if (MessageBox.Show("是否保存当前图片的处理结果" + "?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
  323. {
  324. if (oldmat != null)
  325. {
  326. ////Document doc = Document.FromMat(oldmat);
  327. ////AppWorkspace.ActiveDocumentWorkspace.Document = doc;
  328. //AppWorkspace.ActiveDocumentWorkspace.Refresh();
  329. oldmat.Dispose();
  330. oldmat = null;
  331. }
  332. }
  333. else
  334. {
  335. Document doc = Document.FromMat(oldmat);
  336. AppWorkspace.ActiveDocumentWorkspace.Document = doc;
  337. AppWorkspace.ActiveDocumentWorkspace/*this.documentWorkspace*/.Refresh();
  338. oldmat.Dispose();
  339. oldmat = null;
  340. }
  341. }
  342. if (AppWorkspace.ActiveDocumentWorkspace != null)
  343. {
  344. AppWorkspace.ActiveDocumentWorkspace.GraphicsList.DeleteDrawClass(DrawToolType.DrawScratchTreatmentLine);
  345. if (AppWorkspace.ActiveDocumentWorkspace.AppWorkspace != null)
  346. AppWorkspace.ActiveDocumentWorkspace.AppWorkspace.RefreshLabelListDialog();
  347. AppWorkspace.ActiveDocumentWorkspace.Refresh();
  348. }
  349. if (AppWorkspace.ActiveDocumentWorkspace != null)
  350. {
  351. AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.Pointer;
  352. }
  353. //this.Close();
  354. }
  355. /// <summary>
  356. /// 应用按钮点击方法
  357. /// </summary>
  358. /// <param name="sender"></param>
  359. /// <param name="e"></param>
  360. private void button3_Click(object sender, EventArgs e)
  361. {
  362. if (oldmat != null)
  363. {
  364. AppWorkspace.ActiveDocumentWorkspace.Refresh();
  365. oldmat.Dispose();
  366. oldmat = null;
  367. }
  368. this.Close();
  369. //if (this.AppWorkspace.ActiveDocumentWorkspace == null)
  370. //{
  371. // MessageBox.Show("请打开图片");
  372. // return;
  373. //}
  374. //PaintDotNet.Annotation.ISurfaceBox drawArea = AppWorkspace.ActiveDocumentWorkspace;
  375. //if (drawArea != null && drawArea.GraphicsList != null && drawArea.GraphicsList.Count > 0)
  376. //{
  377. // for (int i = drawArea.GraphicsList.Count - 1; i >= 0; i--)
  378. // {
  379. // if (drawArea.GraphicsList[i].drawToolType == DrawToolType.DrawScratchTreatmentLine/*drawArea.GraphicsList[i].Selected == true*/)
  380. // {
  381. // if (applyImp(drawArea.GraphicsList[i].startPoint, drawArea.GraphicsList[i].endPoint))
  382. // {
  383. // this.Close();
  384. // }
  385. // break;
  386. // }
  387. // }
  388. //}
  389. }
  390. /// <summary>
  391. /// 应用方法实现
  392. /// </summary>
  393. /// <param name="startP"></param>
  394. /// <param name="endP"></param>
  395. private bool applyImp(PointF startP, PointF endP, bool undoAction, int paramWidth)
  396. {
  397. if (action.MenuId == ActionType.ScratchTreatment)//划痕处理
  398. {
  399. if (oldmat == null)
  400. {
  401. oldmat = OpenCvSharp.Extensions.BitmapConverter.ToMat(AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap()/*this.bitmap*/).Clone();
  402. }
  403. //痕宽
  404. //int paramWidth;
  405. if (undoAction || int.TryParse(textBox1.Text, out paramWidth))
  406. {
  407. if (paramWidth < 1)
  408. {
  409. MessageBox.Show(PdnResources.GetString("Menu.Pleaseinpuanumbergreaterthan0.Text"));
  410. return false;
  411. }
  412. }
  413. else
  414. {
  415. MessageBox.Show(PdnResources.GetString("Menu.Pleaseinpuanumbergreaterthan0.Text"));
  416. return false;
  417. }
  418. if (undoAction)
  419. {
  420. OperationsList.RemoveAt(OperationsList.Count - 1);
  421. this.button5.Enabled = OperationsList.Count > 0;
  422. OpenCvSharp.Mat matUndo = new Mat();
  423. for (int i = 0; i < OperationsList.Count; i++)
  424. {
  425. int[] operationItem = OperationsList[i];
  426. Mat imageMaskUndo = new Mat(oldmat.Size(), MatType.CV_8UC1, new Scalar(0));
  427. try
  428. {
  429. Cv2.Line(imageMaskUndo, operationItem[1], operationItem[2], operationItem[3], operationItem[4], new Scalar(255), operationItem[0]);
  430. matUndo = action.PerformMaskCal((i == 0) ? oldmat : matUndo, imageMaskUndo);
  431. }
  432. catch (Exception)
  433. {
  434. matUndo = oldmat.Clone();
  435. }
  436. finally
  437. {
  438. //if (mat != null) mat.Dispose();
  439. if (imageMaskUndo != null) imageMaskUndo.Dispose();
  440. GC.Collect();
  441. }
  442. }
  443. if (OperationsList.Count == 0)
  444. matUndo = oldmat.Clone();
  445. //Cv2.ImShow("test", mat);
  446. Document doc = Document.FromMat(matUndo);
  447. AppWorkspace.ActiveDocumentWorkspace.Document = doc;
  448. //移除
  449. AppWorkspace.ActiveDocumentWorkspace.GraphicsList.DeleteDrawClass(DrawToolType.DrawScratchTreatmentLine);
  450. //刷新
  451. AppWorkspace.ActiveDocumentWorkspace.Refresh();
  452. AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.DrawScratchTreatmentLine;
  453. return true;
  454. }
  455. else
  456. OperationsList.Add(new int[] { paramWidth, (int)startP.X, (int)startP.Y, (int)endP.X, (int)endP.Y });
  457. this.button5.Enabled = OperationsList.Count > 0;
  458. OpenCvSharp.Mat mat = new Mat();
  459. Mat imageMask = new Mat(oldmat.Size(), MatType.CV_8UC1, new Scalar(0));
  460. try
  461. {
  462. ////通过阈值处理生成Mask
  463. //Cv2.Threshold(imageGray, imageMask, 120, 255, ThresholdTypes.Binary);
  464. Cv2.Line(imageMask, (int)startP.X, (int)startP.Y, (int)endP.X, (int)endP.Y, new Scalar(255), paramWidth);
  465. Mat calmat = undoAction ? oldmat : OpenCvSharp.Extensions.BitmapConverter.ToMat(AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap()).Clone();
  466. mat = action.PerformMaskCal(calmat, imageMask);
  467. //Cv2.ImShow("test", mat);
  468. Document doc = Document.FromMat(mat);
  469. AppWorkspace.ActiveDocumentWorkspace.Document = doc;
  470. //移除
  471. AppWorkspace.ActiveDocumentWorkspace.GraphicsList.DeleteDrawClass(DrawToolType.DrawScratchTreatmentLine);
  472. //刷新
  473. AppWorkspace.ActiveDocumentWorkspace.Refresh();
  474. AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.DrawScratchTreatmentLine;
  475. }
  476. catch (Exception)
  477. {
  478. }
  479. finally
  480. {
  481. if (mat != null) mat.Dispose();
  482. if (imageMask != null) imageMask.Dispose();
  483. GC.Collect();
  484. }
  485. return true;
  486. }
  487. return false;
  488. }
  489. /// <summary>
  490. /// 确定按钮点击方法
  491. /// </summary>
  492. /// <param name="sender"></param>
  493. /// <param name="e"></param>
  494. private void button4_Click(object sender, EventArgs e)
  495. {
  496. ////测试景深融合程序
  497. //List<string> ImagePaths = new List<string>();
  498. //foreach (string Path in System.IO.Directory.GetFiles(@"C:\Users\win10SSD\Desktop\工作目录\显微镜\最新版景深融合翻译\11\"))
  499. //{
  500. // ImagePaths.Add(Path);
  501. //}
  502. ////
  503. //Mat[] Coll_Ori = new Mat[ImagePaths.Count];
  504. ////
  505. //for (int index = 0; index < ImagePaths.Count; index++)
  506. //{
  507. // Mat Src = Cv2.ImRead(ImagePaths[index]);
  508. // //原始图
  509. // Coll_Ori[index] = Src;
  510. //}
  511. //Mat mat = Merge.GetMergeMat(Coll_Ori);
  512. //Document doc = Document.FromMat(mat);
  513. //AppWorkspace.ActiveDocumentWorkspace.Document = doc;
  514. //AppWorkspace.ActiveDocumentWorkspace/*this.documentWorkspace*/.Refresh();
  515. //foreach (Mat src1 in Coll_Ori)
  516. //{
  517. // src1.Dispose();
  518. //}
  519. //mat.Dispose();
  520. //GC.Collect();
  521. //return;
  522. if (this.AppWorkspace.ActiveDocumentWorkspace == null)
  523. {
  524. MessageBox.Show(PdnResources.GetString("Menu.Pleaseopenthepicture.Text"));
  525. return;
  526. }
  527. //痕宽
  528. int paramWidth;
  529. if (int.TryParse(textBox1.Text, out paramWidth))
  530. {
  531. if (paramWidth < 1)
  532. {
  533. MessageBox.Show(PdnResources.GetString("Menu.Pleaseinpuanumbergreaterthan0.Text"));
  534. return;
  535. }
  536. }
  537. else
  538. {
  539. MessageBox.Show(PdnResources.GetString("Menu.Pleaseinpuanumbergreaterthan0.Text"));
  540. return;
  541. }
  542. //读取参数信息
  543. for (int i = 0; i < action.lists.Count; i++)
  544. {
  545. Base.Args args = action.lists[i];
  546. switch (args.Key)
  547. {
  548. case "InpaintRadius":
  549. args.Value = paramWidth/*inpaintRadius*/ + "";
  550. break;
  551. }
  552. }
  553. PaintDotNet.Annotation.ISurfaceBox drawArea = AppWorkspace.ActiveDocumentWorkspace;
  554. if (drawArea != null && drawArea.GraphicsList != null && drawArea.GraphicsList.Count > 0)
  555. {
  556. for (int i = drawArea.GraphicsList.Count - 1; i >= 0; i--)
  557. {
  558. if (drawArea.GraphicsList[i].drawToolType == DrawToolType.DrawScratchTreatmentLine/*drawArea.GraphicsList[i].Selected == true*/)
  559. {
  560. applyImp(drawArea.GraphicsList[i].startPoint, drawArea.GraphicsList[i].endPoint, false, -1);
  561. break;
  562. }
  563. }
  564. }
  565. }
  566. protected override void WndProc(ref Message m)
  567. {
  568. if (m.Msg == 0x0112/*WM_SYSCOMMAND*/)
  569. {
  570. //if (m.WParam.ToInt32() == SC_MINIMIZE) //是否点击最小化
  571. //{
  572. // //这里写操作代码
  573. // this.Visible = false; //隐藏窗体
  574. // return;
  575. //}
  576. //if (m.WParam.ToInt32() == SC_MAXIMIZE) //是否点击最大化
  577. //{
  578. // //.....................
  579. //}
  580. if (m.WParam.ToInt32() == 0xf060/*NativeConstants.SC_CLOSE*/) //是否点击关闭
  581. {
  582. //关闭时发生的事件
  583. if (oldmat != null)
  584. {
  585. Document doc = Document.FromMat(oldmat);
  586. AppWorkspace.ActiveDocumentWorkspace.Document = doc;
  587. AppWorkspace.ActiveDocumentWorkspace/*this.documentWorkspace*/.Refresh();
  588. oldmat.Dispose();
  589. oldmat = null;
  590. }
  591. }
  592. }
  593. base.WndProc(ref m);
  594. //if (this.formEx == null)
  595. //{
  596. // base.WndProc(ref m);
  597. //}
  598. //else if (!this.formEx.HandleParentWndProc(ref m))
  599. //{
  600. // OurWndProc(ref m);
  601. //}
  602. }
  603. /// <summary>
  604. /// 撤销按钮点击方法
  605. /// </summary>
  606. /// <param name="sender"></param>
  607. /// <param name="e"></param>
  608. private void button5_Click(object sender, EventArgs e)
  609. {
  610. if (oldmat != null && OperationsList.Count > 0)
  611. {
  612. int[] operationItem = OperationsList[OperationsList.Count - 1];
  613. applyImp(new PointF(operationItem[1], operationItem[2])/*drawArea.GraphicsList[i].startPoint*/, new PointF(operationItem[3], operationItem[4])/*drawArea.GraphicsList[i].endPoint*/, true, operationItem[0]);
  614. //Document doc = Document.FromMat(oldmat);
  615. //AppWorkspace.ActiveDocumentWorkspace.Document = doc;
  616. //AppWorkspace.ActiveDocumentWorkspace.Refresh();
  617. //oldmat.Dispose();
  618. //oldmat = null;
  619. }
  620. else
  621. this.button5.Enabled = false;
  622. //this.Close();
  623. }
  624. /// <summary>
  625. /// skip按钮
  626. /// 显示直方图时,忽略黑色的灰度或颜色值。
  627. /// 这使您可以为背景为黑色的图像实现有意义的直方图显示。
  628. /// </summary>
  629. /// <param name="sender"></param>
  630. /// <param name="e"></param>
  631. private void skipButton_Click(object sender, EventArgs e)
  632. {
  633. //if (this.AppWorkspace.ActiveDocumentWorkspace == null)
  634. //{
  635. // MessageBox.Show("请打开图片");
  636. // return;
  637. //}
  638. foreach (SelectButton selectBtn in this.listButton)
  639. {
  640. if (selectBtn == sender)
  641. {
  642. //设置按钮的选中/非选择的状态
  643. s6Button.BtnSelect = false;// true;
  644. }
  645. else
  646. {
  647. s6Button.BtnSelect = false;
  648. }
  649. this.textBox1.Text = ((SelectButton)sender).BtnText;
  650. }
  651. ////设置按钮的选中/非选择的状态
  652. //s6Button.BtnSelect = !s6Button.BtnSelect;
  653. //this.AppWorkspace.ActiveDocumentWorkspace.HistogramSkipEnabled = s6Button.BtnSelect;
  654. }
  655. private void ScratchTreatmentDialog_FormClosing(object sender, FormClosingEventArgs e)
  656. {
  657. this.AppWorkspace.toolBar.RefreshBtnSelect(false, "ScratchTreatment");
  658. this.AppWorkspace.toolsPanel.RefreshBtnSelect(false, "ScratchTreatment");
  659. }
  660. }
  661. }