123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736 |
- using PaintDotNet.Processing;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace PaintDotNet.Instrument
- {
- internal class ImageComparison : PdnBaseForm
- {
- private GroupBox groupBox1;
- private Button button2;
- private GroupBox groupBox2;
- private GroupBox groupBox3;
- private GroupBox groupBox4;
- private Button button4;
- private Button button3;
- private Button button6;
- private Button button5;
- private PictureBox pictureBox1;
- private TrackBar trackBar1;
- private Button button7;
- private PictureBox pictureBox2;
- private TrackBar trackBar2;
- private Button button8;
- private Button button1;
- private PictureBox pictureBox3;
- /// <summary>
- /// 图片选择窗口
- /// </summary>
- private InterImagePickerDialog imagePickerDialog;
- /// <summary>
- /// 第一个小picturebox的原图
- /// </summary>
- private Bitmap bitmap1;
- /// <summary>
- /// 第二个小picturebox的原图
- /// </summary>
- private Bitmap bitmap2;
- /// <summary>
- /// 合并之后的图片
- /// </summary>
- private Bitmap combineBitmap;
- /// <summary>
- /// 合并时所使用的修改过透明度的图片数组
- /// </summary>
- private Bitmap[] bitArray = new Bitmap[2];
- /// <summary>
- /// 判断两张图片的绘制顺序
- /// </summary>
- private bool ordered = true;
- /// <summary>
- /// 文件名排序
- /// </summary>
- string stepLength = "00" + Startup.instance.step_length;
- /// <summary>
- /// 判断当前点击的按钮是哪个小picturebox的
- /// </summary>
- private int pictureBoxNum = 0;
- private AppWorkspace appWorkspace;
- public ImageComparison(AppWorkspace appWorkspace)
- {
- this.appWorkspace = appWorkspace;
- InitializeComponent();
- InitializeLanguageText();
- }
- private void InitializeLanguageText()
- {
- this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
- this.button2.Text = PdnResources.GetString("Menu.Createpicture.text");
- this.button1.Text = PdnResources.GetString("Menu.File.Close.Text");
- this.groupBox2.Text = PdnResources.GetString("Menu.tool.imagecomparison.compareresults.text");
- this.groupBox3.Text = PdnResources.GetString("Menu.picture.Text");
- this.button4.Text = PdnResources.GetString("Menu.Gallery.text");
- this.button3.Text = PdnResources.GetString("Menu.harddisk.text");
- this.groupBox4.Text = PdnResources.GetString("Menu.picture.Text");
- this.button6.Text = PdnResources.GetString("Menu.Gallery.text");
- this.button5.Text = PdnResources.GetString("Menu.harddisk.text");
- this.Text = PdnResources.GetString("Menu.Tools.PictureComparison.Text");
- }
- private void InitializeComponent()
- {
- this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.button2 = new System.Windows.Forms.Button();
- this.button1 = new System.Windows.Forms.Button();
- this.groupBox2 = new System.Windows.Forms.GroupBox();
- this.pictureBox3 = new System.Windows.Forms.PictureBox();
- this.groupBox3 = new System.Windows.Forms.GroupBox();
- this.button7 = new System.Windows.Forms.Button();
- this.trackBar1 = new System.Windows.Forms.TrackBar();
- this.pictureBox1 = new System.Windows.Forms.PictureBox();
- this.button4 = new System.Windows.Forms.Button();
- this.button3 = new System.Windows.Forms.Button();
- this.groupBox4 = new System.Windows.Forms.GroupBox();
- this.button8 = new System.Windows.Forms.Button();
- this.trackBar2 = new System.Windows.Forms.TrackBar();
- this.pictureBox2 = new System.Windows.Forms.PictureBox();
- this.button6 = new System.Windows.Forms.Button();
- this.button5 = new System.Windows.Forms.Button();
- this.groupBox1.SuspendLayout();
- this.groupBox2.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).BeginInit();
- this.groupBox3.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
- this.groupBox4.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.trackBar2)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit();
- this.SuspendLayout();
- //
- // groupBox1
- //
- this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- 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(621, 55);
- this.groupBox1.TabIndex = 0;
- this.groupBox1.TabStop = false;
- this.groupBox1.Text = "操作";
- //
- // button2
- //
- this.button2.Anchor = System.Windows.Forms.AnchorStyles.Right;
- this.button2.Location = new System.Drawing.Point(426, 20);
- 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.Anchor = System.Windows.Forms.AnchorStyles.Right;
- this.button1.Location = new System.Drawing.Point(524, 20);
- 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.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox2.Controls.Add(this.pictureBox3);
- this.groupBox2.Location = new System.Drawing.Point(13, 75);
- this.groupBox2.Name = "groupBox2";
- this.groupBox2.Size = new System.Drawing.Size(383, 469);
- this.groupBox2.TabIndex = 1;
- this.groupBox2.TabStop = false;
- this.groupBox2.Text = "对比结果";
- //
- // pictureBox3
- //
- this.pictureBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.pictureBox3.Location = new System.Drawing.Point(7, 21);
- this.pictureBox3.Name = "pictureBox3";
- this.pictureBox3.Size = new System.Drawing.Size(370, 434);
- this.pictureBox3.TabIndex = 0;
- this.pictureBox3.TabStop = false;
- //
- // groupBox3
- //
- this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox3.Controls.Add(this.button7);
- this.groupBox3.Controls.Add(this.trackBar1);
- this.groupBox3.Controls.Add(this.pictureBox1);
- this.groupBox3.Controls.Add(this.button4);
- this.groupBox3.Controls.Add(this.button3);
- this.groupBox3.Location = new System.Drawing.Point(402, 75);
- this.groupBox3.Name = "groupBox3";
- this.groupBox3.Size = new System.Drawing.Size(232, 232);
- this.groupBox3.TabIndex = 2;
- this.groupBox3.TabStop = false;
- this.groupBox3.Text = "图片";
- //
- // button7
- //
- this.button7.Location = new System.Drawing.Point(197, 181);
- this.button7.Name = "button7";
- this.button7.Size = new System.Drawing.Size(23, 23);
- this.button7.TabIndex = 4;
- this.button7.Text = "↑";
- this.button7.UseVisualStyleBackColor = true;
- this.button7.Click += new System.EventHandler(this.button7_Click);
- //
- // trackBar1
- //
- this.trackBar1.Cursor = System.Windows.Forms.Cursors.Hand;
- this.trackBar1.Location = new System.Drawing.Point(6, 181);
- this.trackBar1.Maximum = 255;
- this.trackBar1.Name = "trackBar1";
- this.trackBar1.Size = new System.Drawing.Size(185, 45);
- this.trackBar1.TabIndex = 3;
- this.trackBar1.TickStyle = System.Windows.Forms.TickStyle.None;
- this.trackBar1.Value = 125;
- this.trackBar1.Scroll += new System.EventHandler(this.trackBar1_Scroll);
- //
- // pictureBox1
- //
- this.pictureBox1.Location = new System.Drawing.Point(7, 47);
- this.pictureBox1.Name = "pictureBox1";
- this.pictureBox1.Size = new System.Drawing.Size(219, 127);
- this.pictureBox1.TabIndex = 2;
- this.pictureBox1.TabStop = false;
- //
- // button4
- //
- this.button4.Location = new System.Drawing.Point(125, 20);
- this.button4.Name = "button4";
- this.button4.Size = new System.Drawing.Size(67, 21);
- this.button4.TabIndex = 1;
- this.button4.Text = "图库";
- this.button4.UseVisualStyleBackColor = true;
- this.button4.Click += new System.EventHandler(this.button4_Click);
- //
- // button3
- //
- this.button3.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- this.button3.Location = new System.Drawing.Point(52, 20);
- this.button3.Name = "button3";
- this.button3.Size = new System.Drawing.Size(67, 21);
- this.button3.TabIndex = 0;
- this.button3.Text = "硬盘";
- this.button3.UseVisualStyleBackColor = true;
- this.button3.Click += new System.EventHandler(this.button3_Click);
- //
- // groupBox4
- //
- this.groupBox4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox4.Controls.Add(this.button8);
- this.groupBox4.Controls.Add(this.trackBar2);
- this.groupBox4.Controls.Add(this.pictureBox2);
- this.groupBox4.Controls.Add(this.button6);
- this.groupBox4.Controls.Add(this.button5);
- this.groupBox4.Location = new System.Drawing.Point(402, 313);
- this.groupBox4.Name = "groupBox4";
- this.groupBox4.Size = new System.Drawing.Size(231, 231);
- this.groupBox4.TabIndex = 3;
- this.groupBox4.TabStop = false;
- this.groupBox4.Text = "图片";
- //
- // button8
- //
- this.button8.Location = new System.Drawing.Point(197, 181);
- this.button8.Name = "button8";
- this.button8.Size = new System.Drawing.Size(23, 23);
- this.button8.TabIndex = 4;
- this.button8.Text = "↑";
- this.button8.UseVisualStyleBackColor = true;
- this.button8.Click += new System.EventHandler(this.button8_Click);
- //
- // trackBar2
- //
- this.trackBar2.Cursor = System.Windows.Forms.Cursors.Hand;
- this.trackBar2.Location = new System.Drawing.Point(7, 181);
- this.trackBar2.Maximum = 255;
- this.trackBar2.Name = "trackBar2";
- this.trackBar2.Size = new System.Drawing.Size(185, 45);
- this.trackBar2.TabIndex = 3;
- this.trackBar2.TickStyle = System.Windows.Forms.TickStyle.None;
- this.trackBar2.Value = 125;
- this.trackBar2.Scroll += new System.EventHandler(this.trackBar2_Scroll);
- //
- // pictureBox2
- //
- this.pictureBox2.Location = new System.Drawing.Point(7, 47);
- this.pictureBox2.Name = "pictureBox2";
- this.pictureBox2.Size = new System.Drawing.Size(219, 127);
- this.pictureBox2.TabIndex = 2;
- this.pictureBox2.TabStop = false;
- //
- // button6
- //
- this.button6.Location = new System.Drawing.Point(125, 20);
- this.button6.Name = "button6";
- this.button6.Size = new System.Drawing.Size(67, 21);
- this.button6.TabIndex = 1;
- this.button6.Text = "图库";
- this.button6.UseVisualStyleBackColor = true;
- this.button6.Click += new System.EventHandler(this.button6_Click);
- //
- // button5
- //
- this.button5.Location = new System.Drawing.Point(52, 20);
- this.button5.Name = "button5";
- this.button5.Size = new System.Drawing.Size(67, 21);
- this.button5.TabIndex = 0;
- this.button5.Text = "硬盘";
- this.button5.UseVisualStyleBackColor = true;
- this.button5.Click += new System.EventHandler(this.button5_Click);
- //
- // ImageComparison
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
- this.ClientSize = new System.Drawing.Size(646, 556);
- this.Controls.Add(this.groupBox4);
- this.Controls.Add(this.groupBox3);
- this.Controls.Add(this.groupBox2);
- this.Controls.Add(this.groupBox1);
- this.MinimizeBox = false;
- this.Name = "ImageComparison";
- this.Text = "图片对比";
- this.Resize += new System.EventHandler(this.ImageComparison_Resize);
- this.Controls.SetChildIndex(this.groupBox1, 0);
- this.Controls.SetChildIndex(this.groupBox2, 0);
- this.Controls.SetChildIndex(this.groupBox3, 0);
- this.Controls.SetChildIndex(this.groupBox4, 0);
- this.groupBox1.ResumeLayout(false);
- this.groupBox2.ResumeLayout(false);
- ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).EndInit();
- this.groupBox3.ResumeLayout(false);
- this.groupBox3.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
- this.groupBox4.ResumeLayout(false);
- this.groupBox4.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.trackBar2)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit();
- this.ResumeLayout(false);
- }
- /// <summary>
- /// 关闭按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button1_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- /// <summary>
- /// 第一张小图的图库选择按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button4_Click(object sender, EventArgs e)
- {
- //辅助判断点击的是第一个picturebox对应的按钮
- pictureBoxNum = 1;
- ImagePickerDialog(sender);
- }
- /// <summary>
- /// 第二张小图的图库选择按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button6_Click(object sender, EventArgs e)
- {
- //辅助判断点击的是第二个picturebox对应的按钮
- pictureBoxNum = 2;
- ImagePickerDialog(sender);
- }
- /// <summary>
- /// 弹出图库选择窗口
- /// </summary>
- /// <param name="sender"></param>
- private void ImagePickerDialog(object sender)
- {
- if (imagePickerDialog == null)
- {
- imagePickerDialog = new InterImagePickerDialog(this.appWorkspace);
- imagePickerDialog.StartPosition = FormStartPosition.Manual;
- imagePickerDialog.Left = ((Button)sender).Left + 12 + this.Left + this.groupBox2.Width;
- switch (pictureBoxNum)
- {
- case 1:
- imagePickerDialog.Top = ((Button)sender).Bottom + 46 + this.Top + this.groupBox1.Height;
- break;
- case 2:
- imagePickerDialog.Top = ((Button)sender).Bottom + 50 + this.Top + this.groupBox1.Height + this.groupBox3.Height;
- break;
- }
- 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 + this.groupBox2.Width;
- switch (pictureBoxNum)
- {
- case 1:
- imagePickerDialog.Top = ((Button)sender).Bottom + 46 + this.Top + this.groupBox1.Height;
- break;
- case 2:
- imagePickerDialog.Top = ((Button)sender).Bottom + 50 + this.Top + this.groupBox1.Height + this.groupBox3.Height;
- break;
- }
- 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)
- {
- switch (pictureBoxNum)
- {
- case 1:
- this.bitmap1 = ((DocumentWorkspace)sender).CompositionSurface.CreateAliasedBitmap();
- if (bitmap1.Width > pictureBox1.Size.Width || bitmap1.Height > pictureBox1.Size.Height)
- {
- pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
- }
- else
- {
- pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
- }
- this.pictureBox1.Image = this.bitmap1;
- CombinePicture();
- break;
- case 2:
- this.bitmap2 = ((DocumentWorkspace)sender).CompositionSurface.CreateAliasedBitmap();
- if (bitmap2.Width > pictureBox2.Size.Width || bitmap2.Height > pictureBox2.Size.Height)
- {
- pictureBox2.SizeMode = PictureBoxSizeMode.Zoom;
- }
- else
- {
- pictureBox2.SizeMode = PictureBoxSizeMode.CenterImage;
- }
- this.pictureBox2.Image = this.bitmap2;
- CombinePicture();
- break;
- }
- }
- }
- /// <summary>
- /// 第一张小图的硬盘选择图片按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button3_Click(object sender, EventArgs e)
- {
- pictureBoxNum = 1;
- Bitmap newBit1 = ChooseImageFromHardDisk();//暂时接收一下,如果为空则不替换原有的原图对象
- if (newBit1 != null)
- {
- this.bitmap1 = newBit1;
- if (bitmap1.Width > pictureBox1.Size.Width || bitmap1.Height > pictureBox1.Size.Height)
- {
- pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
- }
- else
- {
- pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
- }
- this.pictureBox1.Image = this.bitmap1;
- CombinePicture();
- }
- }
- /// <summary>
- /// 第二张小图的硬盘选择图片按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button5_Click(object sender, EventArgs e)
- {
- pictureBoxNum = 2;
- Bitmap newBit2 = ChooseImageFromHardDisk();//暂时接收一下,如果为空则不替换原有的原图对象
- if (newBit2 != null)
- {
- this.bitmap2 = newBit2;
- if (bitmap2.Width > pictureBox2.Size.Width || bitmap2.Height > pictureBox2.Size.Height)
- {
- pictureBox2.SizeMode = PictureBoxSizeMode.Zoom;
- }
- else
- {
- pictureBox2.SizeMode = PictureBoxSizeMode.CenterImage;
- }
- this.pictureBox2.Image = this.bitmap2;
- CombinePicture();
- }
- }
- /// <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>
- /// <param name="image"></param>
- /// <param name="opcity"></param>
- /// <returns></returns>
- private Bitmap GetTransparencyImage(Image image, int opcity)
- {
- if (opcity < 0 || opcity > 255)
- return null;
- if (image == null)
- return null;
- float imgTransparency = float.Parse(opcity.ToString()) / 255;
- float[][] nArray ={ new float[] {1, 0, 0, 0, 0},
- new float[] {0, 1, 0, 0, 0},
- new float[] {0, 0, 1, 0, 0},
- new float[] {0, 0, 0, imgTransparency, 0},
- new float[] {0, 0, 0, 0, 1}};
- ColorMatrix matrix = new ColorMatrix(nArray);
- ImageAttributes attributes = new ImageAttributes();
- attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
- Bitmap resultImage = new Bitmap(image.Width, image.Height);
- Graphics g = Graphics.FromImage(resultImage);
- g.DrawImage(image, new Rectangle(0, 0, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes);
- return resultImage;
- }
- /// <summary>
- /// 第一张小图的透明度滚动条
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void trackBar1_Scroll(object sender, EventArgs e)
- {
- if (this.pictureBox1.Image != null)
- {
- CombinePicture();
- }
- }
- /// <summary>
- /// 第二张小图的透明度滚动条
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void trackBar2_Scroll(object sender, EventArgs e)
- {
- if (this.pictureBox2.Image != null)
- {
- CombinePicture();
- }
- }
- /// <summary>
- /// 合并两个小picturebox的图片
- /// </summary>
- private void CombinePicture()
- {
- if (this.pictureBox1.Image == null && this.pictureBox2.Image == null)
- return;
- if (this.pictureBox1.Image != null && this.pictureBox2.Image == null)
- {
- combineBitmap = GetTransparencyImage(this.pictureBox1.Image, this.trackBar1.Value);
- ordered = true;
- }
- if (this.pictureBox2.Image != null && this.pictureBox1.Image == null)
- {
- combineBitmap = GetTransparencyImage(this.pictureBox2.Image, this.trackBar2.Value);
- ordered = false;
- }
- if (this.pictureBox1.Image != null && this.pictureBox2.Image != null)
- {
- bitArray[0] = GetTransparencyImage(this.pictureBox1.Image, this.trackBar1.Value);
- bitArray[1] = GetTransparencyImage(this.pictureBox2.Image, this.trackBar2.Value);
- int[] widthArr = new int[] { bitArray[0].Width, bitArray[1].Width };
- int[] heightArr = new int[] { bitArray[0].Height, bitArray[1].Height };
- combineBitmap = new Bitmap(widthArr.Max(), heightArr.Max());
- Graphics g = Graphics.FromImage(combineBitmap);
- if (ordered)
- {
- g.DrawImage(bitArray[0], new PointF(0, 0));
- g.DrawImage(bitArray[1], new PointF(0, 0));
- }
- else
- {
- g.DrawImage(bitArray[1], new PointF(0, 0));
- g.DrawImage(bitArray[0], new PointF(0, 0));
- }
- }
- if (combineBitmap.Width > pictureBox3.Size.Width || combineBitmap.Height > pictureBox3.Size.Height)
- {
- pictureBox3.SizeMode = PictureBoxSizeMode.Zoom;
- }
- else
- {
- pictureBox3.SizeMode = PictureBoxSizeMode.CenterImage;
- }
- this.pictureBox3.Image = combineBitmap;
- }
- /// <summary>
- /// 第一张小图的层级向上按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button7_Click(object sender, EventArgs e)
- {
- if (this.pictureBox1.Image != null && this.pictureBox2.Image != null)
- {
- reverseOrder();
- CombinePicture();
- }
- }
- /// <summary>
- /// 第二个小图的层级向上按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button8_Click(object sender, EventArgs e)
- {
- if (this.pictureBox1.Image != null && this.pictureBox2.Image != null)
- {
- reverseOrder();
- CombinePicture();
- }
- }
- /// <summary>
- /// 反转图片的绘制顺序
- /// </summary>
- private void reverseOrder()
- {
- if (ordered)
- {
- ordered = false;
- }
- else
- {
- ordered = true;
- }
- }
- /// <summary>
- /// 创建图片
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button2_Click(object sender, EventArgs e)
- {
- if (combineBitmap != null)
- {
- DocumentWorkspace dw = this.appWorkspace.AddNewDocumentWorkspace();
- dw.Document = Document.FromImageMat(Camera.Tools.ToMat(combineBitmap));
- dw.xmlSaveModel = Startup.instance.ruleDB;
- dw.InitRulerInfo();
- stepLength = "00" + Startup.instance.step_length;
- // TODO ZYH 这里的图像名称,需要走系统的配置
- dw.fileText = this.Text + "-" + stepLength;
- this.appWorkspace.ActiveDocumentWorkspace = dw;
- //this.appWorkspace.ActiveDocumentWorkspace.PanelBottom.documentStrip.ShowPictures = false;
- this.appWorkspace.ActiveDocumentWorkspace.Refresh();
- Startup.instance.step_length += 1;
- }
- }
- /// <summary>
- /// 窗体尺寸改变后重新判断合并图片的显示方式
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void ImageComparison_Resize(object sender, EventArgs e)
- {
- if (combineBitmap != null)
- {
- if (combineBitmap.Width > pictureBox3.Size.Width || combineBitmap.Height > pictureBox3.Size.Height)
- {
- pictureBox3.SizeMode = PictureBoxSizeMode.Zoom;
- }
- else
- {
- pictureBox3.SizeMode = PictureBoxSizeMode.CenterImage;
- }
- this.pictureBox3.Invalidate();
- }
- }
- }
- }
|