123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458 |
- 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.groupBoxStep2Operate);
- this.Controls.Add(this.groupBox3);
- this.Controls.Add(this.groupBox2);
- this.Controls.Add(this.groupBox1);
- this.Controls.Add(this.groupBox6);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
- this.MaximizeBox = false;
- this.MinimizeBox = false;
- this.Name = "ImageMosaicsDialog";
- this.Text = "图像拼接";
- 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.groupBoxStep2Operate, 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>
- /// 限制只可以输入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;
- }
- }
- }
- /// <summary>
- /// 修改水平个数刷新panel
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- this.panel1.Controls.Clear();
- AddPitureboxTools();
- ReloadStepTwoControls();
- }
- /// <summary>
- /// 修改垂直个数刷新panel
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void textBox2_TextChanged(object sender, EventArgs e)
- {
- this.panel1.Controls.Clear();
- AddPitureboxTools();
- ReloadStepTwoControls();
- }
- /// <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[i] = OpenCvSharp.Extensions.BitmapConverter.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.FromImage(cutBitmap);
- dw.Document = document;
- dw.xmlSaveModel = Startup.instance.ruleDB;
- dw.InitRulerInfo();
- dw.fileText = this.textBox3.Text;
- appWorkspace.ActiveDocumentWorkspace = dw;
- }
- }
- }
- /// <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;
- }
- }
- }
- }
|