123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929 |
- using PaintDotNet.Base.CommTool;
- using PaintDotNet.ImageCollect.CameraEDOF;
- 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.Instrument
- {
- /// <summary>
- /// 三维显示
- /// </summary>
- internal class ImageThreeDShowDialog : PdnBaseForm
- {
- private GroupBox groupBox2;
- private Button button6;
- private Button button5;
- private Button button4;
- private GroupBox groupBox3;
- private Panel panel1;
- private PictureBox pictureBox1;
- /// <summary>
- /// 辅助判断目前最新一个自定义控件的tag值
- /// </summary>
- private int toolsNum = 1;
- /// <summary>
- /// 图片选择窗口
- /// </summary>
- private PaintDotNet.Processing.InterImagePickerDialog imagePickerDialog;
- /// <summary>
- /// 辅助为合并的图片命名
- /// </summary>
- private int nameNum = 1;
- /// <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 Bitmap depthBitmap;
- private Button button1;
- private AppWorkspace appWorkspace;
- private List<decimal> bitsHeight = new List<decimal>();
- public ImageThreeDShowDialog(AppWorkspace appWorkspace)
- {
- this.appWorkspace = appWorkspace;
- InitializeComponent();
- InitializeLanguageText();
- InitializeOtherInfo();
- AddDepthExtensionPicTools();
- }
- private void InitializeLanguageText()
- {
- this.groupBox2.Text = PdnResources.GetString("Menu.operation.text");
- //this.groupBox2.Text = PdnResources.GetString("Menu.Selectimagefrom.text");
- this.button1.Text = PdnResources.GetString("Menu.tool.Generateshortcut.Importconfiguration.text");
- this.button6.Text = PdnResources.GetString("Menu.Currentsoftware.text");
- this.button5.Text = PdnResources.GetString("Menu.Theharddiskimage.Text");
- this.button4.Text = PdnResources.GetString("Menu.3Dimagegeneration.text");
- this.groupBox3.Text = PdnResources.GetString("Menu.Imagelist.Text");
- this.Text = PdnResources.GetString("Menu.3ddisplay.Text");
- }
- /// <summary>
- /// 初始化基础控件
- /// </summary>
- private void InitializeComponent()
- {
- this.groupBox2 = new System.Windows.Forms.GroupBox();
- this.button1 = new System.Windows.Forms.Button();
- this.button6 = new System.Windows.Forms.Button();
- this.button5 = new System.Windows.Forms.Button();
- this.button4 = new System.Windows.Forms.Button();
- this.groupBox3 = new System.Windows.Forms.GroupBox();
- this.panel1 = new System.Windows.Forms.Panel();
- this.pictureBox1 = new System.Windows.Forms.PictureBox();
- this.groupBox2.SuspendLayout();
- this.groupBox3.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
- this.SuspendLayout();
- //
- // groupBox2
- //
- this.groupBox2.Controls.Add(this.button1);
- this.groupBox2.Controls.Add(this.button6);
- this.groupBox2.Controls.Add(this.button5);
- this.groupBox2.Controls.Add(this.button4);
- this.groupBox2.Location = new System.Drawing.Point(13, 13);
- this.groupBox2.Name = "groupBox2";
- this.groupBox2.Size = new System.Drawing.Size(623, 60);
- this.groupBox2.TabIndex = 1;
- this.groupBox2.TabStop = false;
- //
- // button1
- //
- this.button1.Location = new System.Drawing.Point(210, 20);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(75, 23);
- this.button1.TabIndex = 2;
- this.button1.UseVisualStyleBackColor = true;
- this.button1.Visible = false;
- this.button1.Click += new System.EventHandler(this.button1_Click);
- //
- // button6
- //
- this.button6.Location = new System.Drawing.Point(306, 20);
- this.button6.Name = "button6";
- this.button6.Size = new System.Drawing.Size(75, 23);
- this.button6.TabIndex = 1;
- this.button6.UseVisualStyleBackColor = true;
- this.button6.Click += new System.EventHandler(this.button6_Click);
- //
- // button5
- //
- this.button5.Location = new System.Drawing.Point(401, 20);
- this.button5.Name = "button5";
- this.button5.Size = new System.Drawing.Size(75, 23);
- this.button5.TabIndex = 0;
- this.button5.UseVisualStyleBackColor = true;
- this.button5.Click += new System.EventHandler(this.button5_Click);
- //
- // button4
- //
- this.button4.Location = new System.Drawing.Point(496, 20);
- this.button4.Name = "button4";
- this.button4.Size = new System.Drawing.Size(105, 23);
- this.button4.TabIndex = 0;
- this.button4.UseVisualStyleBackColor = true;
- this.button4.Click += new System.EventHandler(this.button4_Click);
- //
- // groupBox3
- //
- this.groupBox3.Controls.Add(this.panel1);
- this.groupBox3.Controls.Add(this.pictureBox1);
- this.groupBox3.Location = new System.Drawing.Point(13, 89);
- this.groupBox3.Name = "groupBox3";
- this.groupBox3.Size = new System.Drawing.Size(623, 511);
- this.groupBox3.TabIndex = 2;
- this.groupBox3.TabStop = false;
- this.groupBox3.Text = "预览";
- //
- // 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, 491);
- this.panel1.TabIndex = 0;
- //
- // pictureBox1
- //
- this.pictureBox1.Location = new System.Drawing.Point(6, 14);
- this.pictureBox1.Name = "pictureBox1";
- this.pictureBox1.Size = new System.Drawing.Size(611, 491);
- this.pictureBox1.TabIndex = 0;
- this.pictureBox1.TabStop = false;
- this.pictureBox1.Visible = false;
- //
- // ImageThreeDShowDialog
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
- this.ClientSize = new System.Drawing.Size(648, 612);
- this.Controls.Add(this.groupBox3);
- this.Controls.Add(this.groupBox2);
- this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
- this.MaximizeBox = false;
- this.MinimizeBox = false;
- this.Name = "ImageThreeDShowDialog";
- this.Text = "三维显示";
- this.Controls.SetChildIndex(this.groupBox2, 0);
- this.Controls.SetChildIndex(this.groupBox3, 0);
- this.groupBox2.ResumeLayout(false);
- this.groupBox3.ResumeLayout(false);
- ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
- this.ResumeLayout(false);
- }
- /// <summary>
- /// 初始化其他
- /// </summary>
- private void InitializeOtherInfo()
- {
- 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 AddDepthExtensionPicTools()
- {
- //判断panel上存在几个图片自定义控件
- if (this.panel1.Controls.Count > 0)
- {
- int toolControls = 0;
- foreach (Control C in this.panel1.Controls)
- {
- if (C is DepthExtensionPicTool)
- toolControls++;
- }
- if (toolControls > 0)
- {
- int rowNum = toolControls / 5;//判断行数
- int coloumNum = toolControls % 5;//判断列数
- Point panelScroll = this.panel1.AutoScrollPosition;
- DepthExtensionPicTool depthExtensionPicTool = new DepthExtensionPicTool();
- depthExtensionPicTool.Tag = toolsNum;
- depthExtensionPicTool.Size = new Size(this.panel1.Width / 5 - 6, this.panel1.Width / 5 - 6);
- depthExtensionPicTool.Location = new Point(0 + ((this.panel1.Width / 5 - 4) * coloumNum), 4 + ((this.panel1.Width / 5) * rowNum) + panelScroll.Y);
- 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);
- this.panel1.Controls.Add(depthExtensionPicTool);
- }
- else
- {
- //第一个自定义控件,理论上无法走进这个判断,可删除
- DepthExtensionPicTool depthExtensionPicTool = new DepthExtensionPicTool();
- depthExtensionPicTool.Tag = toolsNum;
- depthExtensionPicTool.Size = new Size(this.panel1.Width / 5 - 6, this.panel1.Width / 5 - 6);
- depthExtensionPicTool.Location = new Point(0, 4);
- 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);
- this.panel1.Controls.Add(depthExtensionPicTool);
- }
- }
- else
- {
- //实例化第一个自定义图片控件,坐标固定
- DepthExtensionPicTool depthExtensionPicTool = new DepthExtensionPicTool();
- depthExtensionPicTool.Tag = toolsNum;
- depthExtensionPicTool.Size = new Size(this.panel1.Width / 5 - 6, this.panel1.Width / 5 - 6);
- depthExtensionPicTool.Location = new Point(0, 4);
- 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);
- this.panel1.Controls.Add(depthExtensionPicTool);
- }
- toolsNum++;
- }
- /// <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;
- AddDepthExtensionPicTools();
- }
- }
- /// <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;
- //判断当前存在几个自定义图片控件
- int toolControls = 0;
- foreach (Control C in this.panel1.Controls)
- {
- if (C is DepthExtensionPicTool)
- toolControls++;
- }
- if (toolControls == 1)
- {
- //只有一个该控件时不删除当前操作控件
- if (parentTool.pictureBox1.Image != null)
- {
- parentTool.pictureBox1.Image = null;
- parentTool.panel2.Visible = true;
- parentTool.panel1.Visible = false;
- }
- }
- else
- {
- this.panel1.Controls.Remove(parentTool);
- ResizeAllDepthTools();
- }
- }
- /// <summary>
- /// 重置所有图片控件的位置
- /// </summary>
- private void ResizeAllDepthTools()
- {
- List<DepthExtensionPicTool> listTools = new List<DepthExtensionPicTool>();
- foreach (Control C in this.panel1.Controls)
- {
- if (C is DepthExtensionPicTool)
- listTools.Add((DepthExtensionPicTool)C);
- }
- Point panelScroll = this.panel1.AutoScrollPosition;//panel的滚轮位置
- for (int i = 0; i < listTools.Count; i++)
- {
- int rowNum = i / 5;//判断行数
- int coloumNum = i % 5;//判断列数
- listTools[i].Location = new Point(0 + ((this.panel1.Width / 5 - 4) * coloumNum), 4 + ((this.panel1.Width / 5) * rowNum) + panelScroll.Y);
- }
- }
- /// <summary>
- /// 图库选择按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button6_Click(object sender, EventArgs e)
- {
- if (imagePickerDialog == null)
- {
- imagePickerDialog = new PaintDotNet.Processing.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 PaintDotNet.Processing.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.panel1.Controls)
- {
- if(C.Tag != null && C is DepthExtensionPicTool)
- {
- int nowNum = Convert.ToInt32(C.Tag);
- if (nowNum == (toolsNum - 1))//取得当前最新的一个图片自定义控件
- {
- DepthExtensionPicTool depthExtensionPicTool = (DepthExtensionPicTool)C;
- 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;
- AddDepthExtensionPicTools();
- return;
- }
- }
- }
- }
- }
- /// <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()
- {
- bitsHeight.Clear();
- 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)
- {
- //查找xml配置文件
- string pPath = null;// System.IO.Path.GetDirectoryName(cmbInput.Text);
- string[] imageNames = openFileDialog.FileNames;
- List<Bitmap> listBitmap = new List<Bitmap>();
- List<string> listBitNames = new List<string>();
- foreach (string imgName in imageNames)
- {
- if (pPath == null)
- pPath = System.IO.Path.GetDirectoryName(imgName);
- Image image = Image.FromFile(imgName);
- listBitmap.Add(new Bitmap(image));
- listBitNames.Add(System.IO.Path.GetFileName(imgName));
- }
- ////没有找到配置文件
- //if (pPath == null)
- // return listBitmap;
- List<System.IO.FileInfo> lst = new List<System.IO.FileInfo>();
- List<System.IO.FileInfo> lstFiles = getFile(pPath, ".xml", lst);
- //没有找到合适的配置文件
- if (lstFiles.Count != 1)
- return listBitmap;
- string xmlPath = null;// pPath + "\\" + /*Path.GetFileNameWithoutExtension(fileName) + */".xml";
- foreach (System.IO.FileInfo shpFile in lstFiles)
- {
- xmlPath = shpFile.FullName;// + "\n";
- }
- //没有找到配置文件
- if (xmlPath == null)
- return listBitmap;
- //如果xml存在
- if (System.IO.File.Exists(xmlPath))
- {
- using (System.IO.Stream shortbarStream = System.IO.File.OpenRead(xmlPath))
- {
- System.IO.StreamReader sr = new System.IO.StreamReader(shortbarStream);
- string xmlNotes = sr.ReadToEnd();
- Base.SettingModel.ZAxisScanModel toolbarXml = XmlSerializeHelper.DESerializer<Base.SettingModel.ZAxisScanModel>(xmlNotes);
- if (toolbarXml.items.Count > 0)
- {
- this.lists.Clear();
- this.lists.AddRange(toolbarXml.items);
- //MessageBox.Show("导入配置成功");
- if (listBitNames.Count > 0)
- {
- for (int names_index = 0; names_index < listBitNames.Count; names_index++)
- {
- bool findNames = false;
- foreach (var itemBits in this.lists)
- if (itemBits.fileName.Contains(listBitNames[names_index]))
- {
- findNames = true;
- bitsHeight.Add(itemBits.height);
- break;
- }
- if (!findNames)
- bitsHeight.Add(decimal.Zero);
- }
- }
- }
- else
- {
- MessageBox.Show("配置文件格式不正确");
- }
- }
- }
- return listBitmap;
- }
- else
- {
- return null;
- }
- }
- /// <summary>
- /// 获得目录下所有文件或指定文件类型文件(包含所有子文件夹)
- /// </summary>
- /// <param name="path">文件夹路径</param>
- /// <param name="extName">扩展名可以多个 例如 .mp3.wma.rm</param>
- /// <returns>List<FileInfo></returns>
- private List<System.IO.FileInfo> getFile(string path, string extName, List<System.IO.FileInfo> lst)
- {
- try
- {
- string[] dir = System.IO.Directory.GetDirectories(path); //文件夹列表
- System.IO.DirectoryInfo fdir = new System.IO.DirectoryInfo(path);
- System.IO.FileInfo[] file = fdir.GetFiles();
- //FileInfo[] file = Directory.GetFiles(path); //文件列表
- if (file.Length != 0 || dir.Length != 0) //当前目录文件或文件夹不为空
- {
- foreach (System.IO.FileInfo f in file) //显示当前目录所有文件
- if (extName.ToLower().IndexOf(f.Extension.ToLower()) >= 0)
- lst.Add(f);
- foreach (string d in dir)
- getFile(d, extName, lst);//递归
- }
- return lst;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- }
- /// <summary>
- /// 硬盘选择图片按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button5_Click(object sender, EventArgs e)
- {
- List<Bitmap> listBitmap = ChooseImagesFromHardDisk();
- if (listBitmap != null && listBitmap.Count > 0)
- {
- for (int i = 0; i < listBitmap.Count; i++)
- {
- foreach (Control C in this.panel1.Controls)
- {
- if (C is DepthExtensionPicTool && Convert.ToInt32(C.Tag) == (toolsNum - 1))//取得当前最新的一个图片自定义控件
- {
- DepthExtensionPicTool latestDepthTool = (DepthExtensionPicTool)C;
- if (listBitmap[i].Width > latestDepthTool.pictureBox1.Size.Width || listBitmap[i].Height > latestDepthTool.pictureBox1.Size.Height)
- {
- latestDepthTool.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
- }
- else
- {
- latestDepthTool.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
- }
- latestDepthTool.pictureBox1.Image = listBitmap[i];
- latestDepthTool.panel2.Visible = false;
- latestDepthTool.panel1.Visible = true;
- AddDepthExtensionPicTools();
- }
- }
- }
- }
- }
- /// <summary>
- /// 生成三维图像按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button4_Click(object sender, EventArgs e)
- {
- if (this.pictureBox1.Visible == true)
- return;
- bool isSameSize = true;
- //Bitmap origin = this.appWorkspace.ActiveDocumentWorkspace.CompositionSurface.CreateAliasedBitmap();
- string mode = "H";
- int maxSize = 640;//用于限制图像大小
- bool needResize = true;//需要限制图像大小
- int bitmapWidth = -1;
- int bitmapHeight = -1;
- //if (origin.Width > origin.Height)
- // mode = "W";
- //Mat OrgImg = PaintDotNet.Camera.Tools.ToMat(this.appWorkspace.ActiveDocumentWorkspace.CompositionSurface.MakeThumbnail(origin, maxSize, maxSize, mode));// OpenCvSharp.Cv2.ImRead(fileName);
- List<Bitmap> listBitmaps = new List<Bitmap>();
- Bitmap originBitmap;
- foreach (Control C in this.panel1.Controls)
- {
- if (C is DepthExtensionPicTool)
- {
- DepthExtensionPicTool depthExtensionPicTool = (DepthExtensionPicTool)C;
- if (depthExtensionPicTool.pictureBox1.Image != null)
- {
- originBitmap = new Bitmap(depthExtensionPicTool.pictureBox1.Image);
- if (bitmapWidth == -1/* && bitmapHeight == -1*/)
- {
- bitmapWidth = originBitmap.Width;
- bitmapHeight = originBitmap.Height;
- if (maxSize >= bitmapHeight && maxSize >= bitmapWidth)
- needResize = false;
- else if (bitmapWidth > bitmapHeight)
- mode = "W";
- }
- else if (bitmapWidth != originBitmap.Width || bitmapHeight != originBitmap.Height)
- {
- isSameSize = false;
- break;
- }
- if (needResize)
- listBitmaps.Add(Surface.MakeThumbnail(originBitmap, maxSize, maxSize, mode));
- else
- listBitmaps.Add(originBitmap);
- }
- }
- }
- if (!isSameSize)//图像宽高不一致
- {
- MessageBox.Show(PdnResources.GetString("Menu.noyizhi.Text"));
- return;
- }
- //没有上传或选择图片不进行下一步
- if (listBitmaps == null || listBitmaps.Count == 0)
- {
- MessageBox.Show(PdnResources.GetString("Menu.pleaseintopicture.Text"));
- return;
- }
- OpenCvSharp.Mat[] mats = new OpenCvSharp.Mat[listBitmaps.Count];
- for (int i = 0; i < listBitmaps.Count; i++)
- {
- mats[i] = PaintDotNet.Camera.Tools.ToMat(listBitmaps[i]);
- }
- String errorMsg = "";
- //if (mats != null && mats.Count() > 0)
- //{
- // Bitmap depthBitmap = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(Merge.GetMergeMat(mats, ref errorMsg));
- // //return depthBitmap;
- //}
- ////else
- //// return null;
- //根据Z轴扫描生成三维图像数据
- //if (this.lists.Count > 0 && this.bitsHeight.Count > 0)
- //{
- // if (mats != null && mats.Count() > 0 && Merge.GetMergeMatHeight(mats, ref errorMsg, this.bitsHeight))
- // SRWindow.Run(this.appWorkspace);
- // return;
- //}
- Form test = Application.OpenForms["SRWindow"];
- if (mats != null && mats.Count() > 0 && Merge.GetMergeMatHeight(mats, ref errorMsg, this.bitsHeight))
- {
- if ((test == null) || (test.IsDisposed))
- {
- SRWindow.Run(this.appWorkspace);
- }
- else
- {
- test.Activate();
- test.WindowState = FormWindowState.Normal;
- }
- }
- }
- /// <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();
- }
- }
- List<Base.SettingModel.ZAxisScanModel.Item> lists = new List<Base.SettingModel.ZAxisScanModel.Item>();
- /// <summary>
- /// 导入配置
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button1_Click(object sender, EventArgs e)
- {
- using (var openFileDialog = new OpenFileDialog { Filter = "*.xml|*.xml" })
- {
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- //openFileDialog.InitialDirectory
- using (System.IO.Stream shortbarStream = System.IO.File.OpenRead(openFileDialog.FileName))
- {
- System.IO.StreamReader sr = new System.IO.StreamReader(shortbarStream);
- string xmlNotes = sr.ReadToEnd();
- Base.SettingModel.ZAxisScanModel toolbarXml = XmlSerializeHelper.DESerializer<Base.SettingModel.ZAxisScanModel>(xmlNotes);
- if (toolbarXml.items.Count > 0)
- {
- this.lists.Clear();
- this.lists.AddRange(toolbarXml.items);
- MessageBox.Show("导入配置成功");
- }
- else
- {
- MessageBox.Show("配置文件格式不正确");
- }
- }
- }
- }
- }
- }
- }
|