| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493 | using PaintDotNet.Adjust;using PaintDotNet.Base.CommTool;using PaintDotNet.Processing.DepthExtensionComponent;using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Reflection;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace PaintDotNet.Processing{    /// <summary>    /// 图像拼接    /// </summary>    internal class ImageMosaicsDialog : PdnBaseForm    {        private Button button1;        private Button button3;        private Button button2;        private Button button4;        private Button button5;        private GroupBox groupBox2;        private Label label1;        private TextBox tbxColunmN;        private Label label2;        private TextBox textBox2;        private GroupBox groupBox3;        private Panel panel1;        private GroupBox groupBox1;        private GroupBox groupBoxStep2Operate;        private Button btnFromFile;        private Button btnFromApp;        private GroupBox groupBox5;        private Panel panel2;        private GroupBox groupBox6;        private GroupBox groupBox7;        private Button button8;        private TextBox textBox3;        private Label label3;        private PictureBox pictureBox1;        private AppWorkspace appWorkspace;        /// <summary>        /// 是否重置picturebox中的矩形尺寸        /// </summary>        private bool _isFirst = true;        /// <summary>        /// 是否为拖动picturebox中的矩形框        /// </summary>        private bool isMoved = false;        /// <summary>        /// 是否为修改picturebox中的矩形框大小        /// </summary>        private bool isResized = false;        /// <summary>        /// 辅助计算偏移量        /// </summary>        private Point _lastPoint = new Point(0, 0);        /// <summary>        /// picturebox中图片对应矩形        /// </summary>        private Rectangle imageRect;        /// <summary>        /// picturebox中选择框对应矩形        /// </summary>        private Rectangle zoomRect;        /// <summary>        /// 命名        /// </summary>        private string stepNumber = "001";        /// <summary>        /// 图片选择窗口        /// </summary>        private InterImagePickerDialog imagePickerDialog;        /// <summary>        /// 拼接后的图片        /// </summary>        private Bitmap _mosaicsImage;        /// <summary>        /// 图片自定义控件判断鼠标是否按下        /// </summary>        private bool isMouseDown = false;        /// <summary>        /// 自定义控件的location        /// </summary>        private Point picToolLocation;        /// <summary>        /// 鼠标的按下位置        /// </summary>        private Point mouseOffset;        /// <summary>        /// 控件拖动前的location        /// </summary>        private Point oldToolLocation;        private Label label4;        private NumericUpDown numOverlapRate;        /// <summary>        /// 控件拖动前的tag值        /// </summary>        private int oldToolTag;        public ImageMosaicsDialog(AppWorkspace appWorkspace)        {            this.appWorkspace = appWorkspace;            InitializeComponent();            InitializeLanguageText();            InitializeOtherInfo();            AddPitureboxTools();            ReloadStepTwoControls();        }        private void InitializeLanguageText()        {            this.button3.Text = PdnResources.GetString("Menu.thirdstep.text");            this.button4.Text = PdnResources.GetString("Menu.Nextstep.text");            this.button5.Text = PdnResources.GetString("Menu.return.text");            this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");            this.button2.Text = PdnResources.GetString("Menu.Secondstep.text");            this.button1.Text = PdnResources.GetString("Menu.firststep.text");            this.groupBox2.Text = PdnResources.GetString("Menu.Setting.Text");            this.label2.Text = PdnResources.GetString("Menu.ImageProcessing.Imagestitching.Thenumberofvertical.text") + ":";            this.label1.Text = PdnResources.GetString("Menu.ImageProcessing.Imagestitching.Thelevelofthenumber.text") + ":";            this.groupBox3.Text = PdnResources.GetString("Menu.Preview.text");            this.groupBoxStep2Operate.Text = PdnResources.GetString("Menu.Selectpicturefrom.text");            this.btnFromFile.Text = PdnResources.GetString("Menu.Harddiskfile.text");            this.btnFromApp.Text = PdnResources.GetString("Menu.Currentsoftware.text");            this.groupBox5.Text = PdnResources.GetString("Menu.Preview.text");            this.groupBox6.Text = PdnResources.GetString("Menu.finish.text");            this.button8.Text = PdnResources.GetString("Menu.File.Save.Text");            this.label3.Text = PdnResources.GetString("Menu.Imagename.text") + ":";            this.groupBox7.Text = PdnResources.GetString("Menu.Preview.text");            this.Text = PdnResources.GetString("Menu.ImageCollection.ImageStitching.Text");        }        /// <summary>        /// 初始化基础控件        /// </summary>        private void InitializeComponent()        {            this.groupBox1 = new System.Windows.Forms.GroupBox();            this.button5 = new System.Windows.Forms.Button();            this.button4 = new System.Windows.Forms.Button();            this.button3 = new System.Windows.Forms.Button();            this.button2 = new System.Windows.Forms.Button();            this.button1 = new System.Windows.Forms.Button();            this.groupBox2 = new System.Windows.Forms.GroupBox();            this.textBox2 = new System.Windows.Forms.TextBox();            this.tbxColunmN = new System.Windows.Forms.TextBox();            this.label2 = new System.Windows.Forms.Label();            this.label1 = new System.Windows.Forms.Label();            this.groupBox3 = new System.Windows.Forms.GroupBox();            this.panel1 = new System.Windows.Forms.Panel();            this.groupBoxStep2Operate = new System.Windows.Forms.GroupBox();            this.numOverlapRate = new System.Windows.Forms.NumericUpDown();            this.label4 = new System.Windows.Forms.Label();            this.btnFromFile = new System.Windows.Forms.Button();            this.btnFromApp = new System.Windows.Forms.Button();            this.groupBox5 = new System.Windows.Forms.GroupBox();            this.panel2 = new System.Windows.Forms.Panel();            this.groupBox6 = new System.Windows.Forms.GroupBox();            this.button8 = new System.Windows.Forms.Button();            this.textBox3 = new System.Windows.Forms.TextBox();            this.label3 = new System.Windows.Forms.Label();            this.groupBox7 = new System.Windows.Forms.GroupBox();            this.pictureBox1 = new System.Windows.Forms.PictureBox();            this.groupBox1.SuspendLayout();            this.groupBox2.SuspendLayout();            this.groupBox3.SuspendLayout();            this.groupBoxStep2Operate.SuspendLayout();            ((System.ComponentModel.ISupportInitialize)(this.numOverlapRate)).BeginInit();            this.groupBox5.SuspendLayout();            this.groupBox6.SuspendLayout();            this.groupBox7.SuspendLayout();            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();            this.SuspendLayout();            //             // groupBox1            //             this.groupBox1.Controls.Add(this.button5);            this.groupBox1.Controls.Add(this.button4);            this.groupBox1.Controls.Add(this.button3);            this.groupBox1.Controls.Add(this.button2);            this.groupBox1.Controls.Add(this.button1);            this.groupBox1.Location = new System.Drawing.Point(13, 13);            this.groupBox1.Name = "groupBox1";            this.groupBox1.Size = new System.Drawing.Size(88, 603);            this.groupBox1.TabIndex = 0;            this.groupBox1.TabStop = false;            this.groupBox1.Text = "操作";            //             // button5            //             this.button5.Location = new System.Drawing.Point(6, 480);            this.button5.Name = "button5";            this.button5.Size = new System.Drawing.Size(75, 23);            this.button5.TabIndex = 4;            this.button5.Text = "返回";            this.button5.UseVisualStyleBackColor = true;            this.button5.Click += new System.EventHandler(this.button5_Click);            //             // button4            //             this.button4.Location = new System.Drawing.Point(6, 517);            this.button4.Name = "button4";            this.button4.Size = new System.Drawing.Size(75, 23);            this.button4.TabIndex = 3;            this.button4.Text = "下一步";            this.button4.UseVisualStyleBackColor = true;            this.button4.Click += new System.EventHandler(this.button4_Click);            //             // button3            //             this.button3.Location = new System.Drawing.Point(7, 124);            this.button3.Name = "button3";            this.button3.Size = new System.Drawing.Size(75, 23);            this.button3.TabIndex = 2;            this.button3.Text = "第三步";            this.button3.UseVisualStyleBackColor = true;            this.button3.Click += new System.EventHandler(this.button3_Click);            //             // button2            //             this.button2.Location = new System.Drawing.Point(7, 86);            this.button2.Name = "button2";            this.button2.Size = new System.Drawing.Size(75, 23);            this.button2.TabIndex = 1;            this.button2.Text = "第二步";            this.button2.UseVisualStyleBackColor = true;            this.button2.Click += new System.EventHandler(this.button2_Click);            //             // button1            //             this.button1.Location = new System.Drawing.Point(7, 48);            this.button1.Name = "button1";            this.button1.Size = new System.Drawing.Size(75, 23);            this.button1.TabIndex = 0;            this.button1.Text = "第一步";            this.button1.UseVisualStyleBackColor = true;            this.button1.Click += new System.EventHandler(this.button1_Click);            //             // groupBox2            //             this.groupBox2.Controls.Add(this.textBox2);            this.groupBox2.Controls.Add(this.tbxColunmN);            this.groupBox2.Controls.Add(this.label2);            this.groupBox2.Controls.Add(this.label1);            this.groupBox2.Location = new System.Drawing.Point(123, 13);            this.groupBox2.Name = "groupBox2";            this.groupBox2.Size = new System.Drawing.Size(623, 60);            this.groupBox2.TabIndex = 1;            this.groupBox2.TabStop = false;            //             // textBox2            //             this.textBox2.Location = new System.Drawing.Point(418, 22);            this.textBox2.Name = "textBox2";            this.textBox2.Size = new System.Drawing.Size(140, 21);            this.textBox2.TabIndex = 3;            this.textBox2.Text = "4";            this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);            this.textBox2.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox2_KeyPress);            //             // tbxColunmN            //             this.tbxColunmN.Location = new System.Drawing.Point(117, 22);            this.tbxColunmN.Name = "tbxColunmN";            this.tbxColunmN.Size = new System.Drawing.Size(140, 21);            this.tbxColunmN.TabIndex = 2;            this.tbxColunmN.Text = "3";            this.tbxColunmN.TextChanged += new System.EventHandler(this.textBox1_TextChanged);            this.tbxColunmN.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);            //             // label2            //             this.label2.AutoSize = true;            this.label2.Location = new System.Drawing.Point(356, 26);            this.label2.Name = "label2";            this.label2.Size = new System.Drawing.Size(0, 12);            this.label2.TabIndex = 1;            //             // label1            //             this.label1.AutoSize = true;            this.label1.Location = new System.Drawing.Point(55, 26);            this.label1.Name = "label1";            this.label1.Size = new System.Drawing.Size(0, 12);            this.label1.TabIndex = 0;            //             // groupBox3            //             this.groupBox3.Controls.Add(this.panel1);            this.groupBox3.Location = new System.Drawing.Point(123, 89);            this.groupBox3.Name = "groupBox3";            this.groupBox3.Size = new System.Drawing.Size(623, 527);            this.groupBox3.TabIndex = 2;            this.groupBox3.TabStop = false;            //             // panel1            //             this.panel1.AutoScroll = true;            this.panel1.BackColor = System.Drawing.Color.Transparent;            this.panel1.Location = new System.Drawing.Point(6, 14);            this.panel1.Name = "panel1";            this.panel1.Size = new System.Drawing.Size(611, 507);            this.panel1.TabIndex = 0;            //             // groupBoxStep2Operate            //             this.groupBoxStep2Operate.Controls.Add(this.numOverlapRate);            this.groupBoxStep2Operate.Controls.Add(this.label4);            this.groupBoxStep2Operate.Controls.Add(this.btnFromFile);            this.groupBoxStep2Operate.Controls.Add(this.btnFromApp);            this.groupBoxStep2Operate.Location = new System.Drawing.Point(123, 13);            this.groupBoxStep2Operate.Name = "groupBoxStep2Operate";            this.groupBoxStep2Operate.Size = new System.Drawing.Size(623, 60);            this.groupBoxStep2Operate.TabIndex = 3;            this.groupBoxStep2Operate.TabStop = false;            //             // numOverlapRate            //             this.numOverlapRate.DecimalPlaces = 2;            this.numOverlapRate.Increment = new decimal(new int[] {            5,            0,            0,            131072});            this.numOverlapRate.Location = new System.Drawing.Point(99, 23);            this.numOverlapRate.Maximum = new decimal(new int[] {            1,            0,            0,            0});            this.numOverlapRate.Minimum = new decimal(new int[] {            5,            0,            0,            131072});            this.numOverlapRate.Name = "numOverlapRate";            this.numOverlapRate.Size = new System.Drawing.Size(60, 21);            this.numOverlapRate.TabIndex = 4;            this.numOverlapRate.Value = new decimal(new int[] {            10,            0,            0,            131072});            //             // label4            //             this.label4.AutoSize = true;            this.label4.Location = new System.Drawing.Point(16, 26);            this.label4.Name = "label4";            this.label4.Size = new System.Drawing.Size(77, 12);            this.label4.TabIndex = 3;            this.label4.Text = "Overlap rate";            //             // btnFromFile            //             this.btnFromFile.Location = new System.Drawing.Point(526, 20);            this.btnFromFile.Name = "btnFromFile";            this.btnFromFile.Size = new System.Drawing.Size(75, 23);            this.btnFromFile.TabIndex = 1;            this.btnFromFile.UseVisualStyleBackColor = true;            this.btnFromFile.Click += new System.EventHandler(this.button7_Click);            //             // btnFromApp            //             this.btnFromApp.Location = new System.Drawing.Point(414, 20);            this.btnFromApp.Name = "btnFromApp";            this.btnFromApp.Size = new System.Drawing.Size(75, 23);            this.btnFromApp.TabIndex = 0;            this.btnFromApp.UseVisualStyleBackColor = true;            this.btnFromApp.Click += new System.EventHandler(this.button6_Click);            //             // groupBox5            //             this.groupBox5.Controls.Add(this.panel2);            this.groupBox5.Location = new System.Drawing.Point(123, 89);            this.groupBox5.Name = "groupBox5";            this.groupBox5.Size = new System.Drawing.Size(623, 527);            this.groupBox5.TabIndex = 4;            this.groupBox5.TabStop = false;            //             // panel2            //             this.panel2.AutoScroll = true;            this.panel2.Location = new System.Drawing.Point(6, 14);            this.panel2.Name = "panel2";            this.panel2.Size = new System.Drawing.Size(611, 507);            this.panel2.TabIndex = 0;            //             // groupBox6            //             this.groupBox6.Controls.Add(this.button8);            this.groupBox6.Controls.Add(this.textBox3);            this.groupBox6.Controls.Add(this.label3);            this.groupBox6.Location = new System.Drawing.Point(123, 13);            this.groupBox6.Name = "groupBox6";            this.groupBox6.Size = new System.Drawing.Size(623, 60);            this.groupBox6.TabIndex = 5;            this.groupBox6.TabStop = false;            this.groupBox6.Text = "设置";            //             // button8            //             this.button8.Location = new System.Drawing.Point(511, 20);            this.button8.Name = "button8";            this.button8.Size = new System.Drawing.Size(75, 23);            this.button8.TabIndex = 2;            this.button8.Text = "保存";            this.button8.UseVisualStyleBackColor = true;            this.button8.Click += new System.EventHandler(this.button8_Click);            //             // textBox3            //             this.textBox3.Location = new System.Drawing.Point(93, 22);            this.textBox3.Name = "textBox3";            this.textBox3.Size = new System.Drawing.Size(167, 21);            this.textBox3.TabIndex = 1;            //             // label3            //             this.label3.AutoSize = true;            this.label3.Location = new System.Drawing.Point(28, 25);            this.label3.Name = "label3";            this.label3.Size = new System.Drawing.Size(65, 12);            this.label3.TabIndex = 0;            this.label3.Text = "图像名称:";            //             // groupBox7            //             this.groupBox7.Controls.Add(this.pictureBox1);            this.groupBox7.Location = new System.Drawing.Point(123, 89);            this.groupBox7.Name = "groupBox7";            this.groupBox7.Size = new System.Drawing.Size(623, 527);            this.groupBox7.TabIndex = 6;            this.groupBox7.TabStop = false;            this.groupBox7.Text = "预览";            //             // pictureBox1            //             this.pictureBox1.Location = new System.Drawing.Point(6, 14);            this.pictureBox1.Name = "pictureBox1";            this.pictureBox1.Size = new System.Drawing.Size(611, 507);            this.pictureBox1.TabIndex = 0;            this.pictureBox1.TabStop = false;            //             // ImageMosaicsDialog            //             this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;            this.ClientSize = new System.Drawing.Size(758, 628);            this.Controls.Add(this.groupBox7);            this.Controls.Add(this.groupBox5);            this.Controls.Add(this.groupBox3);            this.Controls.Add(this.groupBox2);            this.Controls.Add(this.groupBox1);            this.Controls.Add(this.groupBox6);            this.Controls.Add(this.groupBoxStep2Operate);            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;            this.MaximizeBox = false;            this.MinimizeBox = false;            this.Name = "ImageMosaicsDialog";            this.Text = "图像拼接";            this.Controls.SetChildIndex(this.groupBoxStep2Operate, 0);            this.Controls.SetChildIndex(this.groupBox6, 0);            this.Controls.SetChildIndex(this.groupBox1, 0);            this.Controls.SetChildIndex(this.groupBox2, 0);            this.Controls.SetChildIndex(this.groupBox3, 0);            this.Controls.SetChildIndex(this.groupBox5, 0);            this.Controls.SetChildIndex(this.groupBox7, 0);            this.groupBox1.ResumeLayout(false);            this.groupBox2.ResumeLayout(false);            this.groupBox2.PerformLayout();            this.groupBox3.ResumeLayout(false);            this.groupBoxStep2Operate.ResumeLayout(false);            this.groupBoxStep2Operate.PerformLayout();            ((System.ComponentModel.ISupportInitialize)(this.numOverlapRate)).EndInit();            this.groupBox5.ResumeLayout(false);            this.groupBox6.ResumeLayout(false);            this.groupBox6.PerformLayout();            this.groupBox7.ResumeLayout(false);            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();            this.ResumeLayout(false);        }        /// <summary>        /// 初始化其他控件        /// </summary>        private void InitializeOtherInfo()        {            //第一次进入页面的"第一步"按钮样式            this.button1.BackColor = Color.Gray;            this.button1.ForeColor = Color.White;            this.button1.FlatStyle = FlatStyle.Flat;            this.button1.FlatAppearance.BorderSize = 0;            this.groupBoxStep2Operate.Visible = false;            this.groupBox5.Visible = false;            this.groupBox6.Visible = false;            this.groupBox7.Visible = false;            this.pictureBox1.Paint += new PaintEventHandler(pictureBox1_Paint);            this.pictureBox1.MouseDown += new MouseEventHandler(pictureBox1_MouseDown);            this.pictureBox1.MouseMove += new MouseEventHandler(pictureBox1_MouseMove);        }        /// <summary>        /// 加载空白图片控件        /// </summary>        private void AddPitureboxTools()        {            int colNum = this.tbxColunmN.Text == "" ? 0 : Convert.ToInt32(this.tbxColunmN.Text);//列数            if (colNum == 0)            {                MessageBox.Show(PdnResources.GetString("Menu.henumberoflevelsisnotcorrecpleasereset.Text"));                return;            }            int rowNum = this.textBox2.Text == "" ? 0 : Convert.ToInt32(this.textBox2.Text);//行数            if (rowNum == 0)            {                MessageBox.Show(PdnResources.GetString("Menu.Theverticanumberisnotcorrectpleasereset.Text"));                return;            }            Point startPoint = new Point(0, 4);            if (colNum < 5)                startPoint.X = (this.panel1.Width - (116 * colNum)) / (colNum + 1);            int marginTB = 7;//固定的上下边距            //滚动条不用处理,直接刷整个控件?            for (int i = 0; i < colNum; i++)            {                for (int j = 0; j < rowNum; j++)                {                    PictureBox pictureBox = new PictureBox();                    pictureBox.Size = new Size(116, 116);                    if (colNum >= 5)                    {                        pictureBox.Location = new Point((120 * i), startPoint.Y + ((116 + marginTB) * j));                    }                    else//水平数小于5时,边距是动态的                        pictureBox.Location = new Point(startPoint.X + ((startPoint.X + 116) * i), startPoint.Y + ((116 + marginTB) * j));                    pictureBox.BackColor = Color.White;                    this.panel1.Controls.Add(pictureBox);                }            }        }        /// <summary>        /// 修改水平个数刷新panel        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void textBox1_TextChanged(object sender, EventArgs e)        {            if (tbxColunmN.Text.Trim() == "" || textBox2.Text.Trim() == "")            {                return;            }            //tbxColunmN.Invoke(new EventHandler(delegate {            //    tbxColunmN.Text = int.Parse(tbxColunmN.Text) * int.Parse(textBox2.Text) > 1000 ? (int)(1000 / int.Parse(textBox2.Text)) + "" : tbxColunmN.Text;            //}));            if (int.Parse(textBox2.Text) * int.Parse(tbxColunmN.Text) > 1000)            {                tbxColunmN.Text = (int)(1000 / int.Parse(textBox2.Text)) + "";                return;            }            this.panel1.Controls.Clear();            AddPitureboxTools();            ReloadStepTwoControls();            FocusToCaret(tbxColunmN);        }                /// <summary>        /// 修改垂直个数刷新panel        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void textBox2_TextChanged(object sender, EventArgs e)        {            if (tbxColunmN.Text.Trim() == "" || textBox2.Text.Trim() == "")            {                return;            }            //textBox2.Invoke(new EventHandler(delegate {            //    textBox2.Text = int.Parse(textBox2.Text) * int.Parse(tbxColunmN.Text) > 1000 ? (int)(1000 / int.Parse(tbxColunmN.Text)) + "" : textBox2.Text;            //}));            if (int.Parse(textBox2.Text) * int.Parse(tbxColunmN.Text) > 1000)            {                textBox2.Text = (int)(1000 / int.Parse(tbxColunmN.Text)) + "";                return;            }            this.panel1.Controls.Clear();            AddPitureboxTools();            ReloadStepTwoControls();            FocusToCaret(textBox2);        }        /// <summary>        /// 限制只可以输入0-9数字以及退格键        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)        {            if (e.KeyChar != '\b')//这是允许输入退格键             {                int len = this.tbxColunmN.Text.Length;                if (len < 1 && e.KeyChar == '0')                {                    e.Handled = true;                }                else if ((e.KeyChar < '0') || (e.KeyChar > '9'))//这是允许输入0-9数字                 {                    e.Handled = true;                }            }        }        /// <summary>        /// 限制只可以输入0-9数字以及退格键        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void textBox2_KeyPress(object sender, KeyPressEventArgs e)        {            if (e.KeyChar != '\b')//这是允许输入退格键             {                int len = this.textBox2.Text.Length;                if (len < 1 && e.KeyChar == '0')                {                    e.Handled = true;                }                else if ((e.KeyChar < '0') || (e.KeyChar > '9'))//这是允许输入0-9数字                 {                    e.Handled = true;                }            }        }        void FocusToCaret(TextBox txt)        {            txt.Focus();            txt.Select(this.tbxColunmN.TextLength, 0);            txt.ScrollToCaret();        }        /// <summary>        /// 点击当前软件按钮        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button6_Click(object sender, EventArgs e)        {            if (imagePickerDialog == null)            {                imagePickerDialog = new InterImagePickerDialog(this.appWorkspace);                imagePickerDialog.StartPosition = FormStartPosition.Manual;                imagePickerDialog.Left = ((Button)sender).Left + 12 + this.Left;                imagePickerDialog.Top = ((Button)sender).Bottom + 36 + this.Top;                imagePickerDialog.ValueChanged += new System.EventHandler(this.inputMat_ValueChanged);                imagePickerDialog.Show();            }            else            {                if (!imagePickerDialog.IsDisposed)                {                    imagePickerDialog.WindowState = FormWindowState.Normal;                }                else                {                    imagePickerDialog = new InterImagePickerDialog(this.appWorkspace);                    imagePickerDialog.StartPosition = FormStartPosition.Manual;                    imagePickerDialog.Left = ((Button)sender).Left + 12 + this.Left;                    imagePickerDialog.Top = ((Button)sender).Bottom + 36 + this.Top;                    imagePickerDialog.ValueChanged += new System.EventHandler(this.inputMat_ValueChanged);                    imagePickerDialog.Show();                }            }        }        /// <summary>        /// 从图库选择待对照图片        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void inputMat_ValueChanged(object sender, EventArgs e)        {            if (sender is DocumentWorkspace)            {                Bitmap bitmap = ((DocumentWorkspace)sender).CompositionSurface.CreateAliasedBitmap();                foreach (Control C in this.panel2.Controls)                {                    if (C is DepthExtensionPicTool)                    {                        DepthExtensionPicTool depthExtensionPicTool = (DepthExtensionPicTool)C;                        if (depthExtensionPicTool.pictureBox1.Image == null)                        {                            if (bitmap.Width > depthExtensionPicTool.pictureBox1.Size.Width || bitmap.Height > depthExtensionPicTool.pictureBox1.Size.Height)                            {                                depthExtensionPicTool.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;                            }                            else                            {                                depthExtensionPicTool.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;                            }                            depthExtensionPicTool.pictureBox1.Image = bitmap;                            depthExtensionPicTool.panel2.Visible = false;                            depthExtensionPicTool.panel1.Visible = true;                            //根据插入的控件位置修改滚动条                            Point oldScrollPoint = this.panel2.AutoScrollPosition;                            Point scrollPoint = new Point(depthExtensionPicTool.Location.X + Math.Abs(oldScrollPoint.X) + depthExtensionPicTool.Width - this.panel2.Width,                                    depthExtensionPicTool.Location.Y + Math.Abs(oldScrollPoint.Y) + depthExtensionPicTool.Height - this.panel2.Height);                            if (this.panel2.HorizontalScroll.Visible)                                scrollPoint.X += 16;//固定滚动条尺寸,可能不是完全精准                            if (this.panel2.VerticalScroll.Visible)                                scrollPoint.Y += 16;//固定滚动条尺寸,可能不是完全精准                            this.panel2.AutoScrollPosition = scrollPoint;                            return;                        }                    }                }            }        }        /// <summary>        /// 点击硬盘文件按钮        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button7_Click(object sender, EventArgs e)        {            List<Bitmap> listBitmap = ChooseImagesFromHardDisk();            if (listBitmap != null && listBitmap.Count > 0)            {                int addedImgNum = 0;                for (int i = 0; i < listBitmap.Count; i++)                {                    foreach (Control C in this.panel2.Controls)                    {                        if (C is DepthExtensionPicTool)                        {                            DepthExtensionPicTool depthExtensionPicTool = (DepthExtensionPicTool)C;                            if (depthExtensionPicTool.pictureBox1.Image == null)                            {                                if (listBitmap[i].Width > depthExtensionPicTool.pictureBox1.Size.Width || listBitmap[i].Height > depthExtensionPicTool.pictureBox1.Size.Height)                                {                                    depthExtensionPicTool.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;                                }                                else                                {                                    depthExtensionPicTool.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;                                }                                depthExtensionPicTool.pictureBox1.Image = listBitmap[i];                                depthExtensionPicTool.panel2.Visible = false;                                depthExtensionPicTool.panel1.Visible = true;                                addedImgNum++;                                //如果添加的是最后一张图,移动panel的滚动条到该控件位置                                if (addedImgNum == listBitmap.Count)                                {                                    //根据插入的控件位置修改滚动条                                    Point oldScrollPoint = this.panel2.AutoScrollPosition;                                    Point scrollPoint = new Point(depthExtensionPicTool.Location.X + Math.Abs(oldScrollPoint.X) + depthExtensionPicTool.Width - this.panel2.Width,                                            depthExtensionPicTool.Location.Y + Math.Abs(oldScrollPoint.Y) + depthExtensionPicTool.Height - this.panel2.Height);                                    if (this.panel2.HorizontalScroll.Visible)                                        scrollPoint.X += 16;                                    if (this.panel2.VerticalScroll.Visible)                                        scrollPoint.Y += 16;                                    this.panel2.AutoScrollPosition = scrollPoint;                                }                                break;                            }                        }                    }                }            }        }        /// <summary>        /// 从硬盘选择单张图片        /// </summary>        /// <returns></returns>        private Bitmap ChooseImageFromHardDisk()        {            var openFileDialog = new OpenFileDialog { Filter = "*.jpg,*jpeg,*.bmp,*.ico,*.png,*.tif,*.wmf|*.jpg;*jpeg;*.bmp;*.ico;*.png;*.tif;*.wmf" };            if (openFileDialog.ShowDialog() == DialogResult.OK)            {                Image image = Image.FromFile(openFileDialog.FileName);                Bitmap newBit = new Bitmap(image);                return newBit;            }            else            {                return null;            }        }        /// <summary>        /// 从硬盘选择多张图片        /// </summary>        /// <returns></returns>        private List<Bitmap> ChooseImagesFromHardDisk()        {            var openFileDialog = new OpenFileDialog { Filter = "*.jpg,*jpeg,*.bmp,*.ico,*.png,*.tif,*.wmf|*.jpg;*jpeg;*.bmp;*.ico;*.png;*.tif;*.wmf" };            openFileDialog.Multiselect = true;            if (openFileDialog.ShowDialog() == DialogResult.OK)            {                string[] imageNames = openFileDialog.FileNames;                List<Bitmap> listBitmap = new List<Bitmap>();                foreach (string imgName in imageNames)                {                    Image image = Image.FromFile(imgName);                    listBitmap.Add(new Bitmap(image));                }                return listBitmap;            }            else            {                return null;            }        }        /// <summary>        /// 第一步按钮        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button1_Click(object sender, EventArgs e)        {            if (this.groupBox2.Visible && this.groupBox3.Visible)                return;            ChangeButtonStyle(this.button1, this.button2, this.button3);            this.groupBoxStep2Operate.Visible = false;            this.groupBox5.Visible = false;            this.groupBox6.Visible = false;            this.groupBox7.Visible = false;            this.groupBox2.Visible = true;            this.groupBox3.Visible = true;        }        /// <summary>        /// 第二步按钮        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button2_Click(object sender, EventArgs e)        {            if (this.groupBoxStep2Operate.Visible && this.groupBox5.Visible)                return;            ChangeButtonStyle(this.button2, this.button1, this.button3);            this.groupBox2.Visible = false;            this.groupBox3.Visible = false;            this.groupBox6.Visible = false;            this.groupBox7.Visible = false;            this.groupBoxStep2Operate.Visible = true;            this.groupBox5.Visible = true;        }        /// <summary>        /// 初始化第二步的图片自定义控件        /// </summary>        private void ReloadStepTwoControls()        {            this.panel2.Controls.Clear();            if (!string.IsNullOrEmpty(this.tbxColunmN.Text) && !string.IsNullOrEmpty(this.textBox2.Text))            {                int colNum = this.tbxColunmN.Text == "" ? 0 : Convert.ToInt32(this.tbxColunmN.Text);//列数                int rowNum = this.textBox2.Text == "" ? 0 : Convert.ToInt32(this.textBox2.Text);//行数                int toolsTagNum = 1;                Point startPoint = new Point(0, 4);                if (colNum < 5)                    startPoint.X = (this.panel1.Width - (116 * colNum)) / (colNum + 1);                int marginTB = 7;//固定的上下边距                for (int i = 0; i < rowNum; i++)                {                    for (int j = 0; j < colNum; j++)                    {                        DepthExtensionPicTool depthExtensionPicTool = new DepthExtensionPicTool();                        depthExtensionPicTool.Tag = toolsTagNum;                        depthExtensionPicTool.Size = new Size(116, 116);                        if (colNum >= 5)                            depthExtensionPicTool.Location = new Point((120 * j), startPoint.Y + ((116 + marginTB) * i));                        else//水平数小于5时,边距是动态的                            depthExtensionPicTool.Location = new Point(startPoint.X + ((startPoint.X + 116) * j), startPoint.Y + ((116 + marginTB) * i));                        depthExtensionPicTool.panel1.Cursor = Cursors.Hand;                        depthExtensionPicTool.panel1.Paint += new PaintEventHandler(panelDel_Paint);                        depthExtensionPicTool.panel1.Click += new EventHandler(panelDel_Click);                        depthExtensionPicTool.panel2.Cursor = Cursors.Hand;                        depthExtensionPicTool.panel2.Paint += new PaintEventHandler(panelAdd_Paint);                        depthExtensionPicTool.panel2.Click += new EventHandler(panelAdd_Click);                        depthExtensionPicTool.pictureBox1.MouseDown += new MouseEventHandler(picTool_MouseDown);                        depthExtensionPicTool.pictureBox1.MouseMove += new MouseEventHandler(picTool_MouseMove);                        depthExtensionPicTool.pictureBox1.MouseUp += new MouseEventHandler(picTool_MouseUp);                        this.panel2.Controls.Add(depthExtensionPicTool);                        toolsTagNum++;                        if (colNum > 1)//只有一列不绘制"倒置"button                        {                            if (j == colNum - 1)                            {                                Button convertButton = new Button();                                convertButton.Name = "convertButton";                                convertButton.Text = PdnResources.GetString("Menu.ImageProcessing.Imagestitching.upside-down.text");                                convertButton.Tag = i + 1;                                convertButton.Size = new System.Drawing.Size(50, 23);                                if (colNum >= 5)                                    convertButton.Location = new Point((120 * j) + 116 + 10, startPoint.Y + ((116 + marginTB) * i) + 47);                                else                                    convertButton.Location = new Point(startPoint.X + ((startPoint.X + 116) * j) + 116 + 15, startPoint.Y + ((116 + marginTB) * i) + 47);                                convertButton.Click += new EventHandler(convertButton_Click);                                this.panel2.Controls.Add(convertButton);                            }                        }                    }                }            }        }        /// <summary>        /// 图片自定义控件的鼠标按下事件        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void picTool_MouseDown(object sender, MouseEventArgs e)        {            if (e.Button == MouseButtons.Left)            {                isMouseDown = true;                PictureBox pictureBox = (PictureBox)sender;                ((DepthExtensionPicTool)pictureBox.Parent).Cursor = Cursors.SizeAll;                picToolLocation = ((DepthExtensionPicTool)pictureBox.Parent).Location;                oldToolLocation = ((DepthExtensionPicTool)pictureBox.Parent).Location;                oldToolTag = Convert.ToInt32(((DepthExtensionPicTool)pictureBox.Parent).Tag);                mouseOffset = Control.MousePosition;            }        }        /// <summary>        /// 图片自定义控件的鼠标抬起事件        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void picTool_MouseUp(object sender, MouseEventArgs e)        {            if (!isMouseDown) return;//双击选择图片后可能异常进入该事件,不做处理            isMouseDown = false;            PictureBox pictureBox = (PictureBox)sender;            DepthExtensionPicTool depthExtensionPicTool = (DepthExtensionPicTool)pictureBox.Parent;            List<DepthExtensionPicTool> listDepthExtensionPicTool = new List<DepthExtensionPicTool>();            foreach (Control C in this.panel2.Controls)            {                if (C is DepthExtensionPicTool && (DepthExtensionPicTool)C != depthExtensionPicTool)                {                    listDepthExtensionPicTool.Add((DepthExtensionPicTool)C);                }            }            if (listDepthExtensionPicTool != null && listDepthExtensionPicTool.Count > 0)            {                for (int i = 0; i < listDepthExtensionPicTool.Count; i++)                {                    Point toolScreenLocation = listDepthExtensionPicTool[i].Location;                    int toolTag = Convert.ToInt32(listDepthExtensionPicTool[i].Tag);                    Rectangle toolScreenRectangle = new Rectangle(toolScreenLocation.X, toolScreenLocation.Y, 116, 116);//获得自定义控件对应的矩形区域                    Point nowPoint = this.panel2.PointToClient(Control.MousePosition);//将屏幕鼠标点转换为控件坐标点                    if (toolScreenRectangle.Contains(nowPoint) && toolTag != oldToolTag)                    {                        //替换两个控件的location和tag                        depthExtensionPicTool.Location = toolScreenLocation;                        depthExtensionPicTool.Tag = toolTag;                        listDepthExtensionPicTool[i].Location = oldToolLocation;                        listDepthExtensionPicTool[i].Tag = oldToolTag;                        this.panel2.Refresh();                        return;                    }                }            }            //如果鼠标点不与其他自定义控件重合,则当前拖动控件回到原始点            depthExtensionPicTool.Location = oldToolLocation;        }        /// <summary>        /// 图片自定义控件的鼠标拖动事件        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void picTool_MouseMove(object sender, MouseEventArgs e)        {            int _x = 0;            int _y = 0;            if (isMouseDown)            {                Point pt = Control.MousePosition;                _x = mouseOffset.X - pt.X;                _y = mouseOffset.Y - pt.Y;                PictureBox pictureBox = (PictureBox)sender;                ((DepthExtensionPicTool)pictureBox.Parent).Cursor = Cursors.SizeAll;                ((DepthExtensionPicTool)pictureBox.Parent).Location = new Point(picToolLocation.X - _x, picToolLocation.Y - _y);            }        }        /// <summary>        /// 第三步按钮        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button3_Click(object sender, EventArgs e)        {            if (this.groupBox6.Visible && this.groupBox7.Visible)                return;            ChangeButtonStyle(this.button3, this.button1, this.button2);            this.groupBox2.Visible = false;            this.groupBox3.Visible = false;            this.groupBoxStep2Operate.Visible = false;            this.groupBox5.Visible = false;            this.groupBox6.Visible = true;            this.groupBox7.Visible = true;            this.textBox3.Text = PdnResources.GetString("Menu.Image.Text") + "-" + PdnResources.GetString("Menu.ImageCollection.ImageStitching.Text") + "-" + stepNumber;            this.pictureBox1.Image = null;            this._mosaicsImage = null;            //获取第二步的所有图片            List<Bitmap> bitmapList = new List<Bitmap>();            List<int> tagList = new List<int>();            foreach (Control C in this.panel2.Controls)            {                if (C is DepthExtensionPicTool)                {                    DepthExtensionPicTool depthExtensionPicTool = (DepthExtensionPicTool)C;                    if (depthExtensionPicTool.pictureBox1.Image != null)                    {                        bitmapList.Add((Bitmap)(depthExtensionPicTool.pictureBox1.Image));                        tagList.Add((int)depthExtensionPicTool.Tag);                    }                }            }            if (bitmapList.Count < 2)//少于两张图时不做处理            {                MessageBox.Show(PdnResources.GetString("Menu.Imporlessthatwopicturesunabletojoin.Text"));                return;            }            else            {                OpenCvSharp.Mat[] mats = new OpenCvSharp.Mat[bitmapList.Count];                int index = 0;                foreach (Bitmap bitmap in bitmapList)                {                    var i = tagList[index] - 1;                    mats[index] = PaintDotNet.Camera.Tools.ToMat(bitmapList[index]);                    index++;                }                ////进行图片拼接                Boolean errorFlag = false;                //OpenCvSharp.Mat mat = AdjustIntent.MatchPicByXFeatures2D(mats, out errorFlag);                int colNum = this.tbxColunmN.Text == "" ? 0 : Convert.ToInt32(this.tbxColunmN.Text);//列数                double rate = (double)numOverlapRate.Value;                OpenCvSharp.Mat mat = AdjustIntent.MatchPicOneByOne2D(mats, colNum, rate, out errorFlag/*, false*/);                if (errorFlag || mat.Width < 1 || mat.Height < 1)//宽高大于0代表拼接成功,只能操作可拼接的图片                {                    MessageBox.Show(PdnResources.GetString("Menu.ImageMosaicfailed.Text"));                    return;                }                _mosaicsImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat);                if (_mosaicsImage != null)                {                    if (_mosaicsImage.Width > this.pictureBox1.Size.Width || _mosaicsImage.Height > this.pictureBox1.Size.Height)                    {                        this.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;                    }                    else                    {                        this.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;                    }                    this.pictureBox1.Image = _mosaicsImage;                }            }            _lastPoint = new Point(0, 0);            _isFirst = true;        }        /// <summary>        /// 修改第X步的按钮样式        /// </summary>        /// <param name="displayButton">要修改的按钮</param>        /// <param name="hideButton1">要恢复的按钮1</param>        /// <param name="hideButton2">要恢复的按钮2</param>        private void ChangeButtonStyle(Button displayButton, Button hideButton1, Button hideButton2)        {            hideButton1.BackColor = Color.FromArgb(255, 240, 240, 240);            hideButton1.ForeColor = Color.FromArgb(255, 0, 0, 0);            hideButton1.FlatStyle = FlatStyle.Standard;            hideButton1.FlatAppearance.BorderSize = 1;            hideButton2.BackColor = Color.FromArgb(255, 240, 240, 240);            hideButton2.ForeColor = Color.FromArgb(255, 0, 0, 0);            hideButton2.FlatStyle = FlatStyle.Standard;            hideButton2.FlatAppearance.BorderSize = 1;            displayButton.BackColor = Color.Gray;            displayButton.ForeColor = Color.White;            displayButton.FlatStyle = FlatStyle.Flat;            displayButton.FlatAppearance.BorderSize = 0;        }        /// <summary>        /// 绘制删除图标        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void panelDel_Paint(object sender, PaintEventArgs e)        {            Image deleteImg = PdnResources.GetImageResource("Images.ImageStrip.CloseButton.Hot.png").Reference;//从项目中随便找了一个红色的删除图片            if (deleteImg != null)            {                Graphics g = e.Graphics;                g.DrawImage(deleteImg, 0, 0);            }        }        /// <summary>        /// 绘制添加功能的十字线        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void panelAdd_Paint(object sender, PaintEventArgs e)        {            Panel panel = (Panel)sender;            Size panelSize = panel.Size;            Graphics g = e.Graphics;            Pen linePen = new Pen(Color.Black);            linePen.Width = 3;            g.DrawLine(linePen, new Point(0, panelSize.Height / 2), new Point(panelSize.Width, panelSize.Height / 2));            g.DrawLine(linePen, new Point(panelSize.Width / 2, 0), new Point(panelSize.Width / 2, panelSize.Height));            linePen.Dispose();        }        /// <summary>        /// 点击添加标志        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void panelAdd_Click(object sender, EventArgs e)        {            Bitmap bitmap = ChooseImageFromHardDisk();            if (bitmap != null)            {                Panel panel = (Panel)sender;                DepthExtensionPicTool parentTool = (DepthExtensionPicTool)panel.Parent;                if (bitmap.Width > parentTool.pictureBox1.Size.Width || bitmap.Height > parentTool.pictureBox1.Size.Height)                {                    parentTool.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;                }                else                {                    parentTool.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;                }                parentTool.pictureBox1.Image = bitmap;                parentTool.panel2.Visible = false;                parentTool.panel1.Visible = true;            }        }        /// <summary>        /// 点击删除图标        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void panelDel_Click(object sender, EventArgs e)        {            Panel panel = (Panel)sender;            DepthExtensionPicTool parentTool = (DepthExtensionPicTool)panel.Parent;            if (parentTool.pictureBox1.Image != null)            {                parentTool.pictureBox1.Image = null;                parentTool.panel2.Visible = true;                parentTool.panel1.Visible = false;            }        }        /// <summary>        /// 点击倒置按钮        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void convertButton_Click(object sender, EventArgs e)        {            Button convertBtn = (Button)sender;            int rowNum = 0;            if (convertBtn.Tag != null && convertBtn.Tag.ToString().Length > 0)            {                rowNum = Convert.ToInt32(convertBtn.Tag.ToString());//button的tag值确定是第几行            }            if (rowNum > 0)            {                int colNum = this.tbxColunmN.Text == "" ? 0 : Convert.ToInt32(this.tbxColunmN.Text);//列数                //取得点击按钮所在行的图片自定义控件tag的最大值与最小值                int minTag = colNum * (rowNum - 1) + 1;                int maxTag = colNum * rowNum;                //取得所有图片自定义控件的list                List<DepthExtensionPicTool> picToolList = new List<DepthExtensionPicTool>();                foreach (Control C in this.panel2.Controls)                {                    if (C is DepthExtensionPicTool)                    {                        picToolList.Add((DepthExtensionPicTool)C);                    }                }                //取得tag值所对应的图片自定义控件对象                List<DepthExtensionPicTool> convertPicToolList = picToolList.FindAll(a => Convert.ToInt32(a.Tag) >= minTag && Convert.ToInt32(a.Tag) <= maxTag);                convertPicToolList = convertPicToolList.OrderBy(a => a.Location.X).ToList();//按location重新排序                List<Point> locationPoint = new List<Point>(convertPicToolList.Select(a => a.Location).ToList());//取得这些对象的location                //反转后再重新赋回去                locationPoint.Reverse();                for (int j = 0; j < convertPicToolList.Count; j++)                {                    convertPicToolList[j].Location = locationPoint[j];                }                for (int j = 0; j < convertPicToolList.Count / 2; j++)                {                    int tag1 = (int)convertPicToolList[j].Tag;                    convertPicToolList[j].Tag = (int)convertPicToolList[convertPicToolList.Count - j - 1].Tag;                    convertPicToolList[convertPicToolList.Count - j - 1].Tag = tag1;                }            }        }        /// <summary>        /// 保存按钮        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button8_Click(object sender, EventArgs e)        {            if (this.pictureBox1.Image != null && _mosaicsImage != null)            {                double widthRatio = imageRect.Width / (_mosaicsImage.Width * 1d);//缩略图与原图的宽度比                double heightRatio = imageRect.Height / (_mosaicsImage.Height * 1d);//缩略图与原图的高度比                int xc = (this.pictureBox1.Width - this.imageRect.Width) / 2;//缩略图横坐标与控件原点的偏移量                int yc = (this.pictureBox1.Height - this.imageRect.Height) / 2;//缩略图纵坐标与控件原点的偏移量                int cutX = Convert.ToInt32((zoomRect.X - xc) / widthRatio);                int cutY = Convert.ToInt32((zoomRect.Y - yc) / heightRatio);                int cutWidth = Convert.ToInt32(zoomRect.Width / widthRatio);                int cutHeight = Convert.ToInt32(zoomRect.Height / heightRatio);                Bitmap cutBitmap = DrawRulerHelper.KiCut(new Bitmap(this.pictureBox1.Image), cutX, cutY, cutWidth, cutHeight);                if (cutBitmap != null)                {                    DocumentWorkspace dw = appWorkspace.AddNewDocumentWorkspace();                    Document document = Document.FromImageMat(Camera.Tools.ToMat(cutBitmap));                    dw.Document = document;                    dw.xmlSaveModel = Startup.instance.ruleDB;                    dw.InitRulerInfo();                    dw.fileText = this.textBox3.Text;                    appWorkspace.ActiveDocumentWorkspace = dw;                    Startup.instance.step_length += 1;                    stepNumber = "00" + Startup.instance.step_length;                    this.textBox3.Text = PdnResources.GetString("Menu.Image.Text") + "-" + PdnResources.GetString("Menu.ImageCollection.ImageStitching.Text") + "-" + stepNumber;                }            }        }        /// <summary>        /// 绘制picturebox中的矩形框        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void pictureBox1_Paint(object sender, PaintEventArgs e)        {            if (this.pictureBox1.Image != null)            {                Pen rectPen = new Pen(Color.LightGreen);                rectPen.Width = 3;                if (_isFirst)                {                    //获取缩略图对应矩形                    PropertyInfo _ImageRectanglePropert = this.pictureBox1.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic);                    imageRect = (Rectangle)_ImageRectanglePropert.GetValue(this.pictureBox1, null);                    zoomRect = new Rectangle(imageRect.X, imageRect.Y, imageRect.Width, imageRect.Height);                }                e.Graphics.DrawRectangle(rectPen, zoomRect.X, zoomRect.Y, zoomRect.Width - 1, zoomRect.Height - 1);                e.Graphics.FillRectangle(new SolidBrush(Color.Black), new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 7, 7));                rectPen.Dispose();            }        }        /// <summary>        /// 矩形框的选中        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)        {            _lastPoint.X = e.X;            _lastPoint.Y = e.Y;            //是否平移            if (zoomRect.Contains(e.Location) && !new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 7, 7).Contains(e.Location))                isMoved = true;            else                isMoved = false;            //是否调整大小            if (new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 7, 7).Contains(e.Location))                isResized = true;            else                isResized = false;        }        /// <summary>        /// 矩形框的拖动和改变大小        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)        {            //修改鼠标形状            this.pictureBox1.Cursor = Cursors.Default;            if (zoomRect != null)            {                if (zoomRect.Contains(e.Location) && !new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 7, 7).Contains(e.Location))                {                    this.pictureBox1.Cursor = Cursors.SizeAll;                }                if (new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 7, 7).Contains(e.Location))                {                    this.pictureBox1.Cursor = Cursors.SizeNWSE;                }            }            if (e.Button != MouseButtons.Left)                return;            //拖拽            if (zoomRect != null && isMoved)            {                _isFirst = false;                Point p = e.Location;                int dx = p.X - _lastPoint.X;                int dy = p.Y - _lastPoint.Y;                _lastPoint.X = p.X;                _lastPoint.Y = p.Y;                zoomRect.X += dx;                zoomRect.Y += dy;                //控制矩形框不超过缩略图尺寸                int xc = (this.pictureBox1.Width - this.imageRect.Width) / 2;                int yc = (this.pictureBox1.Height - this.imageRect.Height) / 2;                if (zoomRect.X < xc) zoomRect.X = xc;                if (zoomRect.Y < yc) zoomRect.Y = yc;                if (zoomRect.X + zoomRect.Width > imageRect.Width + xc) zoomRect.X = imageRect.Width - zoomRect.Width + xc;                if (zoomRect.Y + zoomRect.Height > imageRect.Height + yc) zoomRect.Y = imageRect.Height - zoomRect.Height + yc;                this.pictureBox1.Refresh();            }            //调整大小            if (zoomRect != null && isResized)            {                _isFirst = false;                Point p = e.Location;                //不允许超出矩形框的原点                if (p.X < zoomRect.X + 5)                {                    p.X = zoomRect.X + 5;                }                if (p.Y < zoomRect.Y + 5)                {                    p.Y = zoomRect.Y + 5;                }                //修改矩形框尺寸                int top = zoomRect.Top;                int left = zoomRect.Left;                int right = zoomRect.Right;                int bottom = zoomRect.Bottom;                right = p.X;                bottom = p.Y;                zoomRect = new Rectangle(left, top, right - left, bottom - top);                //控制矩形框不超过缩略图尺寸                int xc = (this.pictureBox1.Width - this.imageRect.Width) / 2;                int yc = (this.pictureBox1.Height - this.imageRect.Height) / 2;                if (zoomRect.X < xc) zoomRect.X = xc;                if (zoomRect.Y < yc) zoomRect.Y = yc;                if (zoomRect.X + zoomRect.Width > imageRect.Width + xc) zoomRect.Width = imageRect.Width + xc - zoomRect.X;                if (zoomRect.Y + zoomRect.Height > imageRect.Height + yc) zoomRect.Height = imageRect.Height + yc - zoomRect.Y;                this.pictureBox1.Refresh();            }        }        /// <summary>        /// 返回按钮        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button5_Click(object sender, EventArgs e)        {            //第二步            if (this.groupBox6.Visible && this.groupBox7.Visible)            {                this.button2.PerformClick();                return;            }            //第一步            if (this.groupBoxStep2Operate.Visible && this.groupBox5.Visible)            {                this.button1.PerformClick();                return;            }        }        /// <summary>        /// 下一步按钮        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button4_Click(object sender, EventArgs e)        {            //第二步            if (this.groupBox2.Visible && this.groupBox3.Visible)            {                this.button2.PerformClick();                return;            }            //第三步            if (this.groupBoxStep2Operate.Visible && this.groupBox5.Visible)            {                this.button3.PerformClick();                return;            }        }    }}
 |