123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957 |
- using OpenCvSharp;
- using PaintDotNet.Annotation.Enum;
- using PaintDotNet.Base;
- using PaintDotNet.CustomControl;
- using PaintDotNet.Data.Param;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Windows.Forms;
- namespace PaintDotNet.Instrument
- {
- internal class SmudgeTreatmentDialog : FloatingToolForm/*PdnBaseForm*/
- {
- private AppWorkspace AppWorkspace;
- /// <summary>
- /// 当前处理的程序
- /// </summary>
- private ParamObject action;
- /// <summary>
- /// 原图片备份
- /// </summary>
- private Mat oldmat;
- //DrawSmudgeRectangle, //污迹处理-矩形 1
- //DrawSmudgePolygon, //污迹处理-多边形 2
- //DrawSmudgeCircle, //污迹处理-圆形 3
- //DrawSmudgeEllipse, //污迹处理-椭圆 4
- /// <summary>
- /// 将 操作类型的集合放入一个List,通过OperationIndex读取当前操作位置
- /// </summary>
- private List<int> OperationKtypeList = new List<int>();
- /// <summary>
- /// 实现撤销的功能,将处理因子、轮廓X Y W H、或折线上点X Y的集合放入一个List
- /// </summary>
- private List<double[]> OperationsList = new List<double[]>();
- //处理因子
- double inpaintRadius;
- #region 控件相关
- private Button button3;
- private Button button4;
- public Button button5;
- /// <summary>
- /// 操作区控件
- /// </summary>
- private GroupBox groupBox1;
- private GroupBox groupBox2;
- private Label label1;
- private Label label2;
- private RadioButton checkBox1;
- private RadioButton checkBox2;
- private RadioButton checkBox3;
- private RadioButton checkBox4;
- private UserTextBox textBox1;
- private CustomControl.SelectButton s12Button;
- private CustomControl.SelectButton s9Button;
- private CustomControl.SelectButton s6Button;
- private CustomControl.SelectButton logButton;
- private List<SelectButton> listButton = new List<SelectButton>();
- private void InitializeLanguageText()
- {
- this.button3.Text = PdnResources.GetString("Menu.application.text");
- this.button4.Text = PdnResources.GetString("Menu.ensure.text");
- this.button5.Text = "撤销";// PdnResources.GetString("Menu.cancel.text");
- this.label1.Text = PdnResources.GetString("Menu.tool.Stainprocessing.Shapesettings.text") + ":";
- this.label2.Text = PdnResources.GetString("Menu.tool.Stainprocessing.Processingfactor.text") + ":";
- this.checkBox1.Text = PdnResources.GetString("Menu.LabelAction.DrawRectangle.Text");
- this.checkBox2.Text = PdnResources.GetString("Menu.LabelAction.DrawPolygon.Text");
- this.checkBox3.Text = PdnResources.GetString("Menu.circular.Text");
- this.checkBox4.Text = PdnResources.GetString("Menu.LabelAction.DrawEllipse.Text");
- this.listButton.Add(this.s12Button);
- this.listButton.Add(this.s9Button);
- this.listButton.Add(this.s6Button);
- this.listButton.Add(this.logButton);
- }
- private void InitializeComponent()
- {
- this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.label1 = new System.Windows.Forms.Label();
- this.checkBox1 = new System.Windows.Forms.RadioButton();
- this.checkBox2 = new System.Windows.Forms.RadioButton();
- this.checkBox3 = new System.Windows.Forms.RadioButton();
- this.checkBox4 = new System.Windows.Forms.RadioButton();
- this.groupBox2 = new System.Windows.Forms.GroupBox();
- this.label2 = new System.Windows.Forms.Label();
- this.logButton = new PaintDotNet.CustomControl.SelectButton();
- this.s6Button = new PaintDotNet.CustomControl.SelectButton();
- this.s9Button = new PaintDotNet.CustomControl.SelectButton();
- this.s12Button = new PaintDotNet.CustomControl.SelectButton();
- this.textBox1 = new PaintDotNet.CustomControl.UserTextBox();
- this.button3 = new System.Windows.Forms.Button();
- this.button4 = new System.Windows.Forms.Button();
- this.button5 = new System.Windows.Forms.Button();
- this.groupBox1.SuspendLayout();
- this.groupBox2.SuspendLayout();
- this.SuspendLayout();
- //
- // groupBox1
- //
- this.groupBox1.Controls.Add(this.label1);
- this.groupBox1.Controls.Add(this.checkBox1);
- this.groupBox1.Controls.Add(this.checkBox2);
- this.groupBox1.Controls.Add(this.checkBox3);
- this.groupBox1.Controls.Add(this.checkBox4);
- this.groupBox1.Location = new System.Drawing.Point(12, 6);
- this.groupBox1.Name = "groupBox1";
- this.groupBox1.Size = new System.Drawing.Size(301, 74);
- this.groupBox1.TabIndex = 3;
- this.groupBox1.TabStop = false;
- //
- // label1
- //
- this.label1.AutoSize = true;
- this.label1.Location = new System.Drawing.Point(12, 18);
- this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(65, 12);
- this.label1.TabIndex = 9;
- this.label1.Text = "形状设置:";
- //
- // checkBox1
- //
- this.checkBox1.Anchor = System.Windows.Forms.AnchorStyles.Left;
- this.checkBox1.AutoSize = true;
- this.checkBox1.Checked = true;
- this.checkBox1.Location = new System.Drawing.Point(108, 17);
- this.checkBox1.Name = "checkBox1";
- this.checkBox1.Size = new System.Drawing.Size(47, 16);
- this.checkBox1.TabIndex = 5;
- this.checkBox1.TabStop = true;
- this.checkBox1.Text = "矩形";
- this.checkBox1.UseVisualStyleBackColor = true;
- this.checkBox1.CheckedChanged += new System.EventHandler(this.radioButton_CheckedChanged);
- //
- // checkBox2
- //
- this.checkBox2.Anchor = System.Windows.Forms.AnchorStyles.Left;
- this.checkBox2.AutoSize = true;
- this.checkBox2.Location = new System.Drawing.Point(204, 17);
- this.checkBox2.Name = "checkBox2";
- this.checkBox2.Size = new System.Drawing.Size(59, 16);
- this.checkBox2.TabIndex = 16;
- this.checkBox2.Text = "多边形";
- this.checkBox2.UseVisualStyleBackColor = true;
- this.checkBox2.CheckedChanged += new System.EventHandler(this.radioButton_CheckedChanged);
- //
- // checkBox3
- //
- this.checkBox3.Anchor = System.Windows.Forms.AnchorStyles.Left;
- this.checkBox3.AutoSize = true;
- this.checkBox3.Location = new System.Drawing.Point(108, 51);
- this.checkBox3.Name = "checkBox3";
- this.checkBox3.Size = new System.Drawing.Size(47, 16);
- this.checkBox3.TabIndex = 17;
- this.checkBox3.Text = "圆形";
- this.checkBox3.UseVisualStyleBackColor = true;
- this.checkBox3.CheckedChanged += new System.EventHandler(this.radioButton_CheckedChanged);
- //
- // checkBox4
- //
- this.checkBox4.Anchor = System.Windows.Forms.AnchorStyles.Left;
- this.checkBox4.AutoSize = true;
- this.checkBox4.Location = new System.Drawing.Point(204, 51);
- this.checkBox4.Name = "checkBox4";
- this.checkBox4.Size = new System.Drawing.Size(47, 16);
- this.checkBox4.TabIndex = 18;
- this.checkBox4.Text = "椭圆";
- this.checkBox4.UseVisualStyleBackColor = true;
- this.checkBox4.CheckedChanged += new System.EventHandler(this.radioButton_CheckedChanged);
- //
- // groupBox2
- //
- this.groupBox2.Controls.Add(this.label2);
- this.groupBox2.Controls.Add(this.logButton);
- this.groupBox2.Controls.Add(this.s6Button);
- this.groupBox2.Controls.Add(this.s9Button);
- this.groupBox2.Controls.Add(this.s12Button);
- this.groupBox2.Controls.Add(this.textBox1);
- this.groupBox2.Location = new System.Drawing.Point(12, 80);
- this.groupBox2.Name = "groupBox2";
- this.groupBox2.Size = new System.Drawing.Size(301, 80);
- this.groupBox2.TabIndex = 4;
- this.groupBox2.TabStop = false;
- //
- // label2
- //
- this.label2.AutoSize = true;
- this.label2.Location = new System.Drawing.Point(12, 24);
- this.label2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(65, 12);
- this.label2.TabIndex = 10;
- this.label2.Text = "处理因子:";
- //
- // logButton
- //
- this.logButton.BackColor = System.Drawing.SystemColors.ControlDark;
- this.logButton.BtnSelect = false;
- this.logButton.BtnText = "3";
- this.logButton.Location = new System.Drawing.Point(84, 50);
- this.logButton.Name = "logButton";
- this.logButton.Size = new System.Drawing.Size(31, 21);
- this.logButton.TabIndex = 21;
- this.logButton.Click += new System.EventHandler(this.skipButton_Click);
- //
- // s6Button
- //
- this.s6Button.BackColor = System.Drawing.SystemColors.ControlDark;
- this.s6Button.BtnSelect = false;
- this.s6Button.BtnText = "6";
- this.s6Button.Location = new System.Drawing.Point(140, 50);
- this.s6Button.Name = "s6Button";
- this.s6Button.Size = new System.Drawing.Size(31, 21);
- this.s6Button.TabIndex = 20;
- this.s6Button.Click += new System.EventHandler(this.skipButton_Click);
- //
- // s9Button
- //
- this.s9Button.BackColor = System.Drawing.SystemColors.ControlDark;
- this.s9Button.BtnSelect = false;
- this.s9Button.BtnText = "9";
- this.s9Button.Location = new System.Drawing.Point(196, 50);
- this.s9Button.Name = "s9Button";
- this.s9Button.Size = new System.Drawing.Size(31, 21);
- this.s9Button.TabIndex = 30;
- this.s9Button.Click += new System.EventHandler(this.skipButton_Click);
- //
- // s12Button
- //
- this.s12Button.BackColor = System.Drawing.SystemColors.ControlDark;
- this.s12Button.BtnSelect = false;
- this.s12Button.BtnText = "12";
- this.s12Button.Location = new System.Drawing.Point(252, 50);
- this.s12Button.Name = "s12Button";
- this.s12Button.Size = new System.Drawing.Size(31, 21);
- this.s12Button.TabIndex = 31;
- this.s12Button.Click += new System.EventHandler(this.skipButton_Click);
- //
- // textBox1
- //
- this.textBox1.Location = new System.Drawing.Point(84, 18);
- this.textBox1.Name = "textBox1";
- this.textBox1.Size = new System.Drawing.Size(199, 21);
- this.textBox1.TabIndex = 4;
- //
- // button3
- //
- this.button3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.button3.Location = new System.Drawing.Point(240, 173);
- this.button3.Name = "button3";
- this.button3.Size = new System.Drawing.Size(65, 23);
- this.button3.TabIndex = 5;
- this.button3.Text = "应用";
- this.button3.UseVisualStyleBackColor = true;
- this.button3.Click += new System.EventHandler(this.button3_Click);
- //
- // button4
- //
- this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.button4.Location = new System.Drawing.Point(100, 173);
- this.button4.Name = "button4";
- this.button4.Size = new System.Drawing.Size(65, 23);
- this.button4.TabIndex = 6;
- this.button4.Text = "确定";
- this.button4.UseVisualStyleBackColor = true;
- this.button4.Click += new System.EventHandler(this.button4_Click);
- //
- // button5
- //
- this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.button5.Location = new System.Drawing.Point(170, 173);
- this.button5.Name = "button5";
- this.button5.Size = new System.Drawing.Size(65, 23);
- this.button5.TabIndex = 7;
- this.button5.Text = "撤销";
- this.button5.UseVisualStyleBackColor = true;
- this.button5.Click += new System.EventHandler(this.button5_Click);
- //
- // SmudgeTreatmentDialog
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(325, 208);
- this.Controls.Add(this.groupBox2);
- this.Controls.Add(this.groupBox1);
- this.Controls.Add(this.button5);
- this.Controls.Add(this.button4);
- this.Controls.Add(this.button3);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
- this.Margin = new System.Windows.Forms.Padding(6);
- this.Name = "SmudgeTreatmentDialog";
- this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.SmudgeTreatmentDialog_FormClosing);
- this.Controls.SetChildIndex(this.button3, 0);
- this.Controls.SetChildIndex(this.button4, 0);
- this.Controls.SetChildIndex(this.button5, 0);
- this.Controls.SetChildIndex(this.groupBox1, 0);
- this.Controls.SetChildIndex(this.groupBox2, 0);
- this.groupBox1.ResumeLayout(false);
- this.groupBox1.PerformLayout();
- this.groupBox2.ResumeLayout(false);
- this.groupBox2.PerformLayout();
- this.ResumeLayout(false);
- }
- #endregion
- public SmudgeTreatmentDialog(AppWorkspace AppWorkspace)
- {
- this.AppWorkspace = AppWorkspace;
- this.ShowInTaskbar = false;
- InitializeComponent();
- InitializeLanguageText();
- this.Text = PdnResources.GetString("Menu.Tools.SmudgeTreatment.Text");/*;//待修改中文资源-scc备注 20200709*/
- action = new Data.Action.Action1215();
- this.AppWorkspace.ActiveDocumentWorkspaceChanging += new EventHandler(AppWorkspace_ActiveDocumentWorkspaceChanging);
- this.AppWorkspace.ActiveDocumentWorkspaceChanged += new EventHandler(this.ActiveDocumentWorkspaceChanged);
- this.VisibleChanged += new EventHandler(this.SmudgeTreatmentDialog_FormClosed);
- }
- private void SmudgeTreatmentDialog_FormClosed(object sender, EventArgs/*FormClosedEventArgs*/ e)
- {
- if (this.Visible)
- return;
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- AppWorkspace.ActiveDocumentWorkspace.GraphicsList.DeleteDrawClass(DrawToolType.DrawSmudgeRectangle);
- AppWorkspace.ActiveDocumentWorkspace.GraphicsList.DeleteDrawClass(DrawToolType.DrawSmudgeCircle);//#18267
- AppWorkspace.ActiveDocumentWorkspace.GraphicsList.DeleteDrawClass(DrawToolType.DrawSmudgeEllipse);
- AppWorkspace.ActiveDocumentWorkspace.GraphicsList.DeleteDrawClass(DrawToolType.DrawSmudgePolygon);
- if (AppWorkspace.ActiveDocumentWorkspace.AppWorkspace != null)
- AppWorkspace.ActiveDocumentWorkspace.AppWorkspace.RefreshLabelListDialog();
- AppWorkspace.ActiveDocumentWorkspace.Refresh();
- }
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.Pointer;
- }
- }
- private void ActiveDocumentWorkspaceChanged(object sender, EventArgs e)
- {
- if (!this.Visible)
- return;
- RefreshActiveTool();
- }
- public void RefreshActiveTool()
- {
- if (this.AppWorkspace.ActiveDocumentWorkspace != null)
- {
- if (this.checkBox1.Checked)
- {//修改ActiveTool的 时候用大写ActiveTool
- AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.DrawSmudgeRectangle;// DrawSmudgePolygon;// DrawSmudgeEllipse;//
- }
- else if (this.checkBox2.Checked)
- {
- AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.DrawSmudgePolygon;// DrawSmudgeEllipse;//
- }
- else if (this.checkBox3.Checked)
- {
- AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.DrawSmudgeCircle;
- }
- else if (this.checkBox4.Checked)
- {
- AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.DrawSmudgeEllipse;
- }
- }
- //this.PhaseModelsBackUp = this.AppWorkspace.ActiveDocumentWorkspace.PhaseModelsForCopy;
- }
- /// <summary>
- /// 图片切换的处理方法 //#20193
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void AppWorkspace_ActiveDocumentWorkspaceChanging(object sender, EventArgs e)
- {
- if (!this.Visible)
- return;
- if (oldmat != null)
- {
- if (MessageBox.Show("是否保存当前图片的处理结果" + "?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
- {
- if (oldmat != null)
- {
- ////Document doc = Document.FromMat(oldmat);
- ////AppWorkspace.ActiveDocumentWorkspace.Document = doc;
- //AppWorkspace.ActiveDocumentWorkspace.Refresh();
- oldmat.Dispose();
- oldmat = null;
- }
- }
- else
- {
- Document doc = Document.FromMat(oldmat.Clone());
- AppWorkspace.ActiveDocumentWorkspace.Document = doc;
- AppWorkspace.ActiveDocumentWorkspace/*this.documentWorkspace*/.Refresh();
- oldmat.Dispose();
- oldmat = null;
- }
- }
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- AppWorkspace.ActiveDocumentWorkspace.GraphicsList.DeleteDrawClass(DrawToolType.DrawSmudgeRectangle);
- AppWorkspace.ActiveDocumentWorkspace.GraphicsList.DeleteDrawClass(DrawToolType.DrawSmudgeCircle);//#18267
- AppWorkspace.ActiveDocumentWorkspace.GraphicsList.DeleteDrawClass(DrawToolType.DrawSmudgeEllipse);
- AppWorkspace.ActiveDocumentWorkspace.GraphicsList.DeleteDrawClass(DrawToolType.DrawSmudgePolygon);
- if (AppWorkspace.ActiveDocumentWorkspace.AppWorkspace != null)
- AppWorkspace.ActiveDocumentWorkspace.AppWorkspace.RefreshLabelListDialog();
- AppWorkspace.ActiveDocumentWorkspace.Refresh();
- }
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.Pointer;
- }
- //this.Close();
- }
- private bool toApplyMethod()
- {
- if (this.AppWorkspace.ActiveDocumentWorkspace == null)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseopenthepicture.Text"));
- return false;
- }
- //处理因子
- if (double.TryParse(textBox1.Text, out inpaintRadius))
- {
- if (inpaintRadius < 1)
- {
- MessageBox.Show(PdnResources.GetString("Menu.leasenumbergreatethanforprocessingfac.Text"));
- return false;
- }
- }
- else
- {
- MessageBox.Show(PdnResources.GetString("Menu.leasenumbergreatethanforprocessingfac.Text"));
- return false;
- }
- return true;
- }
- /// <summary>
- /// 应用按钮点击方法
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button3_Click(object sender, EventArgs e)
- {
- if (oldmat != null)
- {
- //Document doc = Document.FromMat(oldmat);
- //AppWorkspace.ActiveDocumentWorkspace.Document = doc;
- AppWorkspace.ActiveDocumentWorkspace.Refresh();
- oldmat.Dispose();
- oldmat = null;
- }
- this.Close();
- //if (!toApplyMethod())
- //{
- // return;
- //}
- //this.button4_Click(sender, e);
- //this.Close();
- }
- /// <summary>
- /// 确定按钮点击方法
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button4_Click(object sender, EventArgs e)
- {
- if (!toApplyMethod())
- {
- return;
- }
- //读取参数信息
- for (int i = 0; i < action.lists.Count; i++)
- {
- Base.Args args = action.lists[i];
- switch (args.Key)
- {
- case "InpaintRadius":
- args.Value = inpaintRadius + "";
- break;
- }
- }
- PaintDotNet.Annotation.ISurfaceBox drawArea = AppWorkspace.ActiveDocumentWorkspace;
- if (drawArea != null && drawArea.GraphicsList != null && drawArea.GraphicsList.Count > 0)
- {
- for (int i = drawArea.GraphicsList.Count - 1; i >= 0; i--)
- {
- if (drawArea.GraphicsList[i].drawToolType == DrawToolType.DrawSmudgeRectangle/*DrawSmudgePolygon*//*DrawScratchTreatmentLine*//*drawArea.GraphicsList[i].Selected == true*/)
- {
- applyImp1(drawArea.GraphicsList[i].Rectangle);
- break;
- //drawArea.GraphicsList[i].GetPoints();
- ////drawArea.GraphicsList.RemoveObj(drawArea.GraphicsList[i]);
- }
- else if (drawArea.GraphicsList[i].drawToolType == DrawToolType.DrawSmudgePolygon/*DrawScratchTreatmentLine*//*drawArea.GraphicsList[i].Selected == true*/)
- {
- applyImp2(drawArea.GraphicsList[i].GetPoints());
- break;
- //drawArea.GraphicsList[i].GetPoints();
- ////drawArea.GraphicsList.RemoveObj(drawArea.GraphicsList[i]);
- }
- else if (drawArea.GraphicsList[i].drawToolType == DrawToolType.DrawSmudgeCircle)
- {
- applyImp3(drawArea.GraphicsList[i].Rectangle);
- break;
- }
- else if (drawArea.GraphicsList[i].drawToolType == DrawToolType.DrawSmudgeEllipse)
- {
- applyImp4(drawArea.GraphicsList[i].Rectangle);
- break;
- }
- }
- //drawArea.Refresh();
- }
- }
- protected override void WndProc(ref Message m)
- {
- if (m.Msg == 0x0112/*WM_SYSCOMMAND*/)
- {
- if (m.WParam.ToInt32() == 0xf060/*NativeConstants.SC_CLOSE*/) //是否点击关闭
- {
- //关闭时发生的事件
- if (oldmat != null)
- {
- Document doc = Document.FromMat(oldmat.Clone());
- AppWorkspace.ActiveDocumentWorkspace.Document = doc;
- AppWorkspace.ActiveDocumentWorkspace/*this.documentWorkspace*/.Refresh();
- oldmat.Dispose();
- oldmat = null;
- }
- }
- }
- base.WndProc(ref m);
- }
- /// <summary>
- /// 撤销按钮点击方法
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button5_Click(object sender, EventArgs e)
- {
- if (oldmat != null && OperationsList.Count > 0 && OperationKtypeList.Count == OperationsList.Count)
- {
- OperationsList.RemoveAt(OperationsList.Count - 1);
- OperationKtypeList.RemoveAt(OperationKtypeList.Count - 1);
- Mat matUndo = oldmat;
- for (int i = 0; i < OperationsList.Count; i++)
- {
- double[] opeItem = OperationsList[i];
- double inpaintRadiusUndo = opeItem[0];
- //读取参数信息
- for (int iact = 0; iact < action.lists.Count; iact++)
- {
- Base.Args args = action.lists[iact];
- switch (args.Key)
- {
- case "InpaintRadius":
- args.Value = inpaintRadiusUndo + "";
- break;
- }
- }
- int opeKtype = OperationKtypeList[i];
- if (opeKtype == 1)
- {
- Mat imageMaskUndo = new Mat(oldmat.Size(), MatType.CV_8UC1, new Scalar(0));
- OpenCvSharp.Point[][] arr = new OpenCvSharp.Point[1][];
- arr[0] = new OpenCvSharp.Point[] { new OpenCvSharp.Point(opeItem[1], opeItem[2]), new OpenCvSharp.Point((int)(opeItem[1] + opeItem[3]), opeItem[2]), new OpenCvSharp.Point((int)(opeItem[1]+ opeItem[3]), (int)(opeItem[2]+ opeItem[4])), new OpenCvSharp.Point(opeItem[1], opeItem[2]+ opeItem[4]) };
- Cv2.FillPoly(imageMaskUndo, arr, new Scalar(255));
- matUndo = action.PerformMaskCal(i == 0 ? oldmat : matUndo, imageMaskUndo);
- if (imageMaskUndo != null) imageMaskUndo.Dispose();
- GC.Collect();
- }
- else if (opeKtype == 2)
- {
- Mat imageMask = new Mat(oldmat.Size(), MatType.CV_8UC1, new Scalar(0));
- OpenCvSharp.Point[][] arr = new OpenCvSharp.Point[1][];
- List<PointF> pointArray = new List<PointF>();
- for (int iope = 1; iope < opeItem.Length - 1; iope+=2)
- {
- pointArray.Add(new PointF((float)opeItem[iope], (float)opeItem[iope + 1]));
- }
- arr[0] = Adjust.BaseImage.BaseTools.pointToPoint(pointArray/*points*/).ToArray();
- Cv2.FillPoly(imageMask, arr/*ps*//*pointArray.ToArray()*/, new Scalar(255));
- matUndo = action.PerformMaskCal(i == 0 ? oldmat : matUndo, imageMask);
- if (imageMask != null) imageMask.Dispose();
- GC.Collect();
- }
- else if (opeKtype == 3)
- {
- float radius = (float)((opeItem[3]) < (opeItem[4]) ? (opeItem[3]) : (opeItem[4])) / 2;
- Mat imageMask = new Mat(oldmat.Size(), MatType.CV_8UC1, new Scalar(0));
- Cv2.Circle(imageMask, (int)(opeItem[1] + radius), (int)(opeItem[2] + radius), (int)radius, new Scalar(255), -1);
- matUndo = action.PerformMaskCal(i == 0 ? oldmat : matUndo, imageMask);
- if (imageMask != null) imageMask.Dispose();
- GC.Collect();
- }
- else if (opeKtype == 4)
- {
- Mat imageMask = new Mat(oldmat.Size(), MatType.CV_8UC1, new Scalar(0));
- Cv2.Ellipse(imageMask, new RotatedRect(new Point2f((float)(opeItem[1] + opeItem[1] + opeItem[3]) / 2, (float)(opeItem[2] + opeItem[2] + opeItem[4]) / 2), new Size2f(opeItem[3], opeItem[4]), 0), new Scalar(255), -1);
- matUndo = action.PerformMaskCal(i == 0 ? oldmat : matUndo, imageMask);
- if (imageMask != null) imageMask.Dispose();
- GC.Collect();
- }
- }
- if (OperationsList.Count == 0)
- matUndo = oldmat.Clone();
- Document doc = Document.FromMat(matUndo);
- AppWorkspace.ActiveDocumentWorkspace.Document = doc;
- ////移除
- //AppWorkspace.ActiveDocumentWorkspace.GraphicsList.DeleteDrawClass(DrawToolType.DrawSmudgeRectangle);
- //刷新
- AppWorkspace.ActiveDocumentWorkspace.Refresh();
- //AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.DrawSmudgeRectangle;
- this.button5.Enabled = OperationsList.Count > 0;
- }
- else
- this.button5.Enabled = false;
- //if (oldmat != null)
- //{
- // Document doc = Document.FromMat(oldmat);
- // AppWorkspace.ActiveDocumentWorkspace.Document = doc;
- // AppWorkspace.ActiveDocumentWorkspace/*this.documentWorkspace*/.Refresh();
- // oldmat.Dispose();
- // oldmat = null;
- //}
- //this.Close();
- }
- /// <summary>
- /// check radio改变事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void radioButton_CheckedChanged(object sender, EventArgs e)
- {
- //清空界面现有污迹处理标记
- if (AppWorkspace.ActiveDocumentWorkspace != null)
- {
- /*AppWorkspace.ActiveDocumentWorkspace.tools[(int)DrawToolType.DrawSmudgeRectangle].OnDel2KeyDown(AppWorkspace.ActiveDocumentWorkspace, null);
- AppWorkspace.ActiveDocumentWorkspace.tools[(int)DrawToolType.DrawSmudgePolygon].OnDel2KeyDown(AppWorkspace.ActiveDocumentWorkspace, null);
- AppWorkspace.ActiveDocumentWorkspace.tools[(int)DrawToolType.DrawSmudgeCircle].OnDel2KeyDown(AppWorkspace.ActiveDocumentWorkspace, null);
- AppWorkspace.ActiveDocumentWorkspace.tools[(int)DrawToolType.DrawSmudgeEllipse].OnDel2KeyDown(AppWorkspace.ActiveDocumentWorkspace, null);*/
- if (AppWorkspace.ActiveDocumentWorkspace.AppWorkspace != null)
- AppWorkspace.ActiveDocumentWorkspace.AppWorkspace.RefreshLabelListDialog();
- if (this.checkBox1.Checked)
- {//修改ActiveTool的 时候用大写ActiveTool
- AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.DrawSmudgeRectangle;// DrawSmudgePolygon;// DrawSmudgeEllipse;//
- }
- else if (this.checkBox2.Checked)
- {
- AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.DrawSmudgePolygon;// DrawSmudgeEllipse;//
- }
- else if (this.checkBox3.Checked)
- {
- AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.DrawSmudgeCircle;
- }
- else if (this.checkBox4.Checked)
- {
- AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.DrawSmudgeEllipse;
- }
- }
- ////还原时发生的事件
- //if (oldmat != null)
- //{
- // Document doc = Document.FromMat(oldmat);
- // AppWorkspace.ActiveDocumentWorkspace.Document = doc;
- // AppWorkspace.ActiveDocumentWorkspace/*this.documentWorkspace*/.Refresh();
- // oldmat.Dispose();
- // oldmat = null;
- //}
-
- }
- /// <summary>
- /// 应用方法实现-矩形
- /// </summary>
- /// <param name="startP"></param>
- /// <param name="endP"></param>
- private void applyImp1(RectangleF rectangle, bool undoAction = false)
- {
- if (action.MenuId == ActionType.SmudgeTreatment)//划痕处理
- {
- if (oldmat == null)
- oldmat = AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat().Clone();
- OperationKtypeList.Add(1);
- OperationsList.Add(new double[] { inpaintRadius, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height });
- this.button5.Enabled = OperationsList.Count > 0;
- Mat imageMask = new Mat(oldmat.Size(), MatType.CV_8UC1, new Scalar(0));
- OpenCvSharp.Point[][] arr = new OpenCvSharp.Point[1][];
- arr[0] = new OpenCvSharp.Point[] { new OpenCvSharp.Point(rectangle.X, rectangle.Y), new OpenCvSharp.Point(rectangle.X + rectangle.Width, rectangle.Y), new OpenCvSharp.Point(rectangle.X + rectangle.Width, rectangle.Y + rectangle.Height), new OpenCvSharp.Point(rectangle.X, rectangle.Y + rectangle.Height) };
- Cv2.FillPoly(imageMask, arr, new Scalar(255));
- Mat calMat = AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat().Clone();
- Mat mat = action.PerformMaskCal(calMat, imageMask);
- Document doc = Document.FromMat(mat);
- AppWorkspace.ActiveDocumentWorkspace.Document = doc;
- //移除
- AppWorkspace.ActiveDocumentWorkspace.GraphicsList.DeleteDrawClass(DrawToolType.DrawSmudgeRectangle);
- //刷新
- AppWorkspace.ActiveDocumentWorkspace.Refresh();
- AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.DrawSmudgeRectangle;
- if (imageMask != null) imageMask.Dispose();
- //if (mat != null) mat.Dispose();
- GC.Collect();
- }
- }
- /// <summary>
- /// 应用方法实现-多边形
- /// </summary>
- /// <param name="startP"></param>
- /// <param name="endP"></param>
- private void applyImp2(List<PointF> pointArray, bool undoAction = false)
- {
- if (action.MenuId == ActionType.SmudgeTreatment)//划痕处理
- {
- if (oldmat == null)
- oldmat = AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat().Clone();
- OperationKtypeList.Add(2);
- List<double> itemList = new List<double>();
- itemList.Add(inpaintRadius);
- foreach (PointF item in pointArray)
- {
- itemList.Add(item.X);
- itemList.Add(item.Y);
- }
- OperationsList.Add(itemList.ToArray());
- this.button5.Enabled = OperationsList.Count > 0;
- Mat imageMask = new Mat(oldmat.Size(), MatType.CV_8UC1, new Scalar(0));
- OpenCvSharp.Point[][] arr = new OpenCvSharp.Point[1][];
- arr[0] = Adjust.BaseImage.BaseTools.pointToPoint(pointArray/*points*/).ToArray();
- Cv2.FillPoly(imageMask, arr/*ps*//*pointArray.ToArray()*/, new Scalar(255));
- Mat calMat = AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat().Clone();
- Mat mat = action.PerformMaskCal(calMat, imageMask);
- //Cv2.ImShow("test", mat);
- Document doc = Document.FromMat(mat);
- AppWorkspace.ActiveDocumentWorkspace.Document = doc;
- //移除
- AppWorkspace.ActiveDocumentWorkspace.GraphicsList.DeleteDrawClass(DrawToolType.DrawSmudgePolygon);
- //刷新
- AppWorkspace.ActiveDocumentWorkspace.Refresh();
- AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.DrawSmudgePolygon;
- if (imageMask != null) imageMask.Dispose();
- //if (mat != null) mat.Dispose();
- GC.Collect();
- }
- }
- /// <summary>
- /// 应用方法实现-圆形
- /// </summary>
- /// <param name="startP"></param>
- /// <param name="endP"></param>
- private void applyImp3(RectangleF rectangle, bool undoAction = false)
- {
- if (action.MenuId == ActionType.SmudgeTreatment)//划痕处理
- {
- if (oldmat == null)
- oldmat = AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat().Clone();
- float x1 = rectangle.X;
- float y1 = rectangle.Y;
- float x2 = rectangle.Right;
- float y2 = rectangle.Bottom;
- if (x2 < x1)
- {
- float tmp = x2;
- x2 = x1;
- x1 = tmp;
- }
- if (y2 < y1)
- {
- float tmp = y2;
- y2 = y1;
- y1 = tmp;
- }
- OperationKtypeList.Add(3);
- OperationsList.Add(new double[] { inpaintRadius, x1, y1, x2 - x1, y2 - y1 });
- this.button5.Enabled = OperationsList.Count > 0;
- float radius = ((x2 - x1) < (y2 - y1) ? (x2 - x1) : (y2 - y1)) / 2;
- Mat imageMask = new Mat(oldmat.Size(), MatType.CV_8UC1, new Scalar(0));
- Cv2.Circle(imageMask, (int)(x1 + radius), (int)(y1 + radius), (int)radius, new Scalar(255), -1);
- Mat calMat = AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat().Clone();
- Mat mat = action.PerformMaskCal(calMat, imageMask);
- Document doc = Document.FromMat(mat/*.Clone()*/);
- AppWorkspace.ActiveDocumentWorkspace.Document = doc;
- //移除
- AppWorkspace.ActiveDocumentWorkspace.GraphicsList.DeleteDrawClass(DrawToolType.DrawSmudgeCircle);
- //刷新
- AppWorkspace.ActiveDocumentWorkspace.Refresh();
- AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.DrawSmudgeCircle;
- if (imageMask != null) imageMask.Dispose();
- //if (mat != null) mat.Dispose();
- GC.Collect();
- }
- }
- /// <summary>
- /// 应用方法实现-椭圆
- /// </summary>
- /// <param name="startP"></param>
- /// <param name="endP"></param>
- private void applyImp4(RectangleF rectangle, bool undoAction = false)
- {
- if (action.MenuId == ActionType.SmudgeTreatment)//划痕处理
- {
- if (oldmat == null)
- oldmat = AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat().Clone();
- float x1 = rectangle.X;
- float y1 = rectangle.Y;
- float x2 = rectangle.Right;
- float y2 = rectangle.Bottom;
- if (x2 < x1)
- {
- float tmp = x2;
- x2 = x1;
- x1 = tmp;
- }
- if (y2 < y1)
- {
- float tmp = y2;
- y2 = y1;
- y1 = tmp;
- }
- OperationKtypeList.Add(4);
- OperationsList.Add(new double[] { inpaintRadius, x1, y1, x2 - x1, y2 - y1 });
- this.button5.Enabled = OperationsList.Count > 0;
- Mat imageMask = new Mat(oldmat.Size(), MatType.CV_8UC1, new Scalar(0));
- Cv2.Ellipse(imageMask, new RotatedRect(new Point2f((x1 + x2) / 2, (y1 + y2) / 2), new Size2f(x2 - x1, y2 - y1), 0), new Scalar(255), -1);
- //Cv2.Circle(imageMask, (int)(x1 + radius), (int)(y1 + radius), (int)radius, new Scalar(255), -1);
- Mat calMat = AppWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreatedAliasedMat().Clone();
- Mat mat = action.PerformMaskCal(calMat, imageMask);
- Document doc = Document.FromMat(mat);
- AppWorkspace.ActiveDocumentWorkspace.Document = doc;
- //移除
- AppWorkspace.ActiveDocumentWorkspace.GraphicsList.DeleteDrawClass(DrawToolType.DrawSmudgeEllipse);
- //刷新
- AppWorkspace.ActiveDocumentWorkspace.Refresh();
- AppWorkspace.ActiveDocumentWorkspace.ActiveTool = DrawToolType.DrawSmudgeEllipse;
- if (imageMask != null) imageMask.Dispose();
- //if (mat != null) mat.Dispose();
- GC.Collect();
- }
- }
- /// <summary>
- /// skip按钮
- /// 显示直方图时,忽略黑色的灰度或颜色值。
- /// 这使您可以为背景为黑色的图像实现有意义的直方图显示。
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void skipButton_Click(object sender, EventArgs e)
- {
- //if (this.AppWorkspace.ActiveDocumentWorkspace == null)
- //{
- // MessageBox.Show("请打开图片");
- // return;
- //}
- foreach (SelectButton selectBtn in this.listButton)
- {
- if (selectBtn == sender)
- {
- //设置按钮的选中/非选择的状态
- s6Button.BtnSelect = false;// true;
- }
- else
- {
- s6Button.BtnSelect = false;
- }
- this.textBox1.Text = ((SelectButton)sender).BtnText;
- }
- ////设置按钮的选中/非选择的状态
- //s6Button.BtnSelect = !s6Button.BtnSelect;
- //this.AppWorkspace.ActiveDocumentWorkspace.HistogramSkipEnabled = s6Button.BtnSelect;
- }
- private void SmudgeTreatmentDialog_FormClosing(object sender, FormClosingEventArgs e)
- {
- #region [开启脚本录制]
- if (AppWorkspace.startScriptRecording)
- {
- getScriptRecording();
- }
- #endregion
- this.AppWorkspace.toolBar.RefreshBtnSelect(false, "SmudgeTreatment");
- this.AppWorkspace.toolsPanel.RefreshBtnSelect(false, "SmudgeTreatment");
- }
- #region [脚本录制]
- private void getScriptRecording()
- {
- List<Args> args = action.Lists;
- int menuId = action.MenuId == ActionType.SmudgeTreatment ? 1215 : 1214;
- string text = menuId == 1215 ? "污迹处理" : "划痕处理";
- this.AppWorkspace.SetScriptStartRecording(menuId, text, args);
- }
- #endregion
- }
- }
|