using OpenCvSharp.Extensions;
using PaintDotNet.Instrument.CustomInterface;
using PaintDotNet.Processing;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Entity.Migrations.Model;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization.Formatters.Binary;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PaintDotNet.Instrument
{
///
/// 分栏显示
///
internal class ColumnsShowDialog : PdnBaseForm
{
private GroupBox groupBox1;
private Panel panel1;
private GroupBox groupBox2;
private GroupBox groupBox3;
private Label label1;
private Label label4;
private Panel panel2;
private Label label3;
private Label label2;
private TextBox textBox1;
private ComboBox comboBox1;
private Panel panel3;
private CheckBox checkBox1;
private Button button1;
private TextBox textBox2;
private PictureBox pictureBox1;
private AppWorkspace appWorkspace;
///
/// 自定义控件
///
ColControl colControl1, colControl2, colControl3, colControl4, colControl5, colControl6, colControl7,
colControl8, colControl9;
///
/// 自定义控件的list
///
List listColControl;
///
/// 图像显示数量下拉选项
///
int[] imgCount = new int[] { 2, 3, 4, 6, 8, 9 };
///
/// 调色板
///
PaintDotNet.ColorsForm colorsForm;
///
/// 图片选择窗口
///
private InterImagePickerDialog imagePickerDialog;
///
/// 图片
///
Bitmap newBitmap;
///
/// 辅助判断操作的是哪个按钮
///
private int buttonNum = 0;
///
/// 辅助判断操作的是哪个自定义控件
///
private int colNum = 0;
///
/// picturebox中缩略图与原始图片宽度比例
///
private double widthRatio;
///
/// picturebox中缩略图与原始图片高度比例
///
private double heightRatio;
///
/// 算偏移量使用
///
Point lastPoint = new Point(0, 0);
///
/// picturebox中的图片矩形
///
Rectangle imageRect;
///
/// picturebox中的小矩形框
///
Rectangle zoomRect;
///
/// 判断是否要重新计算picturebox的矩形
///
bool isFirst = true;
///
/// 鼠标move时是否为拖动矩形框
///
bool isSelected = false;
///
/// 鼠标move时是否为修改矩形大小
///
bool isResized = false;
///
/// 临时使用的自定义控件对象
///
ColControl newColtrol = null;
///
/// picturebox中红框的最小宽度(原图放大3200%)
///
private int minRectWidth;
///
/// picturebox中红框的最小高度(原图放大3200%)
///
private int minRectHeight;
///
/// 步长
///
string stepLength = "00" + Startup.instance.step_length;
int imgWidth = 0;
int imgHeight = 0;
public ColumnsShowDialog(AppWorkspace appWorkspace)
{
this.appWorkspace = appWorkspace;
colControl1 = new ColControl();
colControl2 = new ColControl();
colControl3 = new ColControl();
colControl4 = new ColControl();
colControl5 = new ColControl();
colControl6 = new ColControl();
colControl7 = new ColControl();
colControl8 = new ColControl();
colControl9 = new ColControl();
listColControl = new List();
listColControl.Add(colControl1);
listColControl.Add(colControl2);
listColControl.Add(colControl3);
listColControl.Add(colControl4);
listColControl.Add(colControl5);
listColControl.Add(colControl6);
listColControl.Add(colControl7);
listColControl.Add(colControl8);
listColControl.Add(colControl9);
for (int i = 0; i < listColControl.Count; i++)
{
listColControl[i].button.Tag = (i + 1);
listColControl[i].button.Click += new EventHandler(ColControl_Click);
listColControl[i].Tag = (i + 1);
listColControl[i].Click += new EventHandler(ColControl_Click);
listColControl[i].workspaceWindow.panel.Tag = (i + 1);
listColControl[i].workspaceWindow.panel.MouseDown += ColControl_Click;
listColControl[i].workspaceWindow.leftRuler.Tag = (i + 1);
listColControl[i].workspaceWindow.leftRuler.MouseDown += ColControl_Click;
listColControl[i].workspaceWindow.topRuler.Tag = (i + 1);
listColControl[i].workspaceWindow.topRuler.MouseDown += ColControl_Click;
listColControl[i].workspaceWindow.panel.Scroll += new ScrollEventHandler(scrollMovePictureBox);
}
InitializeComponent();
InitializeLanguageText();
InitializeControlData();
InitializeColControls();
}
///
/// 根据下拉菜单选择的图片数量刷新pannel
///
private void InitializeColControls()
{
this.panel1.Controls.Clear();
RefreshColcontrol();
}
private void RefreshColcontrol()
{
int controlCount = imgCount[this.comboBox1.SelectedIndex];
switch (controlCount)
{
case 2:
colControl1.Size = new Size(this.panel1.Width / 2 - 4, this.panel1.Height - 4);
colControl1.Location = new Point(2, 2);
this.panel1.Controls.Add(colControl1);
colControl2.Size = new Size(this.panel1.Width / 2 - 4, this.panel1.Height - 4);
colControl2.Location = new Point(this.panel1.Width / 2 + 2, 2);
this.panel1.Controls.Add(colControl2);
break;
case 3:
colControl1.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height - 4);
colControl1.Location = new Point(2, 2);
this.panel1.Controls.Add(colControl1);
colControl2.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height - 4);
colControl2.Location = new Point(this.panel1.Width / 3 + 2, 2);
this.panel1.Controls.Add(colControl2);
colControl3.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height - 4);
colControl3.Location = new Point(this.panel1.Width / 3 * 2 + 2, 2);
this.panel1.Controls.Add(colControl3);
break;
case 4:
colControl1.Size = new Size(this.panel1.Width / 2 - 4, this.panel1.Height / 2 - 4);
colControl1.Location = new Point(2, 2);
this.panel1.Controls.Add(colControl1);
colControl2.Size = new Size(this.panel1.Width / 2 - 4, this.panel1.Height / 2 - 4);
colControl2.Location = new Point(this.panel1.Width / 2 + 2, 2);
this.panel1.Controls.Add(colControl2);
colControl3.Size = new Size(this.panel1.Width / 2 - 4, this.panel1.Height / 2 - 4);
colControl3.Location = new Point(2, this.panel1.Height / 2 + 2);
this.panel1.Controls.Add(colControl3);
colControl4.Size = new Size(this.panel1.Width / 2 - 4, this.panel1.Height / 2 - 4);
colControl4.Location = new Point(this.panel1.Width / 2 + 2, this.panel1.Height / 2 + 2);
this.panel1.Controls.Add(colControl4);
break;
case 6:
colControl1.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 2 - 4);
colControl1.Location = new Point(2, 2);
this.panel1.Controls.Add(colControl1);
colControl2.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 2 - 4);
colControl2.Location = new Point(this.panel1.Width / 3 + 2, 2);
this.panel1.Controls.Add(colControl2);
colControl3.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 2 - 4);
colControl3.Location = new Point(this.panel1.Width / 3 * 2 + 2, 2);
this.panel1.Controls.Add(colControl3);
colControl4.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 2 - 4);
colControl4.Location = new Point(2, this.panel1.Height / 2 + 2);
this.panel1.Controls.Add(colControl4);
colControl5.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 2 - 4);
colControl5.Location = new Point(this.panel1.Width / 3 + 2, this.panel1.Height / 2 + 2);
this.panel1.Controls.Add(colControl5);
colControl6.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 2 - 4);
colControl6.Location = new Point(this.panel1.Width / 3 * 2 + 2, this.panel1.Height / 2 + 2);
this.panel1.Controls.Add(colControl6);
break;
case 8:
colControl1.Size = new Size(this.panel1.Width / 4 - 4, this.panel1.Height / 2 - 4);
colControl1.Location = new Point(2, 2);
this.panel1.Controls.Add(colControl1);
colControl2.Size = new Size(this.panel1.Width / 4 - 4, this.panel1.Height / 2 - 4);
colControl2.Location = new Point(this.panel1.Width / 4 + 2, 2);
this.panel1.Controls.Add(colControl2);
colControl3.Size = new Size(this.panel1.Width / 4 - 4, this.panel1.Height / 2 - 4);
colControl3.Location = new Point(this.panel1.Width / 4 * 2 + 2, 2);
this.panel1.Controls.Add(colControl3);
colControl4.Size = new Size(this.panel1.Width / 4 - 4, this.panel1.Height / 2 - 4);
colControl4.Location = new Point(this.panel1.Width / 4 * 3 + 2, 2);
this.panel1.Controls.Add(colControl4);
colControl5.Size = new Size(this.panel1.Width / 4 - 4, this.panel1.Height / 2 - 4);
colControl5.Location = new Point(2, this.panel1.Height / 2 + 2);
this.panel1.Controls.Add(colControl5);
colControl6.Size = new Size(this.panel1.Width / 4 - 4, this.panel1.Height / 2 - 4);
colControl6.Location = new Point(this.panel1.Width / 4 + 2, this.panel1.Height / 2 + 2);
this.panel1.Controls.Add(colControl6);
colControl7.Size = new Size(this.panel1.Width / 4 - 4, this.panel1.Height / 2 - 4);
colControl7.Location = new Point(this.panel1.Width / 4 * 2 + 2, this.panel1.Height / 2 + 2);
this.panel1.Controls.Add(colControl7);
colControl8.Size = new Size(this.panel1.Width / 4 - 4, this.panel1.Height / 2 - 4);
colControl8.Location = new Point(this.panel1.Width / 4 * 3 + 2, this.panel1.Height / 2 + 2);
this.panel1.Controls.Add(colControl8);
break;
case 9:
colControl1.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 3 - 4);
colControl1.Location = new Point(2, 2);
this.panel1.Controls.Add(colControl1);
colControl2.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 3 - 4);
colControl2.Location = new Point(this.panel1.Width / 3 + 2, 2);
this.panel1.Controls.Add(colControl2);
colControl3.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 3 - 4);
colControl3.Location = new Point(this.panel1.Width / 3 * 2 + 2, 2);
this.panel1.Controls.Add(colControl3);
colControl4.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 3 - 4);
colControl4.Location = new Point(2, this.panel1.Height / 3 + 2);
this.panel1.Controls.Add(colControl4);
colControl5.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 3 - 4);
colControl5.Location = new Point(this.panel1.Width / 3 + 2, this.panel1.Height / 3 + 2);
this.panel1.Controls.Add(colControl5);
colControl6.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 3 - 4);
colControl6.Location = new Point(this.panel1.Width / 3 * 2 + 2, this.panel1.Height / 3 + 2);
this.panel1.Controls.Add(colControl6);
colControl7.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 3 - 4);
colControl7.Location = new Point(2, this.panel1.Height / 3 * 2 + 2);
this.panel1.Controls.Add(colControl7);
colControl8.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 3 - 4);
colControl8.Location = new Point(this.panel1.Width / 3 + 2, this.panel1.Height / 3 * 2 + 2);
this.panel1.Controls.Add(colControl8);
colControl9.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 3 - 4);
colControl9.Location = new Point(this.panel1.Width / 3 * 2 + 2, this.panel1.Height / 3 * 2 + 2);
this.panel1.Controls.Add(colControl9);
break;
}
}
private void InitializeLanguageText()
{
this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
this.button1.Text = PdnResources.GetString("Menu.Createpicture.text");
this.groupBox2.Text = PdnResources.GetString("Menu.Setting.Text");
this.label4.Text = PdnResources.GetString("Menu.tool.Columndisplay.Numberofimages.text") + ":";
this.label3.Text = PdnResources.GetString("Menu.tool.Columndisplay.Columncolor.text") + ":";
this.label2.Text = PdnResources.GetString("Menu.Pixel.text");
this.label1.Text = PdnResources.GetString("Menu.tool.Columndisplay.imagespacing.text") + ":";
this.groupBox3.Text = PdnResources.GetString("Menu.tool.Columndisplay.Thumbnail.text");
this.checkBox1.Text = PdnResources.GetString("Menu.tool.Columndisplay.synchronousmode.text");
this.Text = PdnResources.GetString("Menu.Tools.ColumnDisplay.Text");
}
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.button1 = new System.Windows.Forms.Button();
this.panel1 = new System.Windows.Forms.Panel();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.label4 = new System.Windows.Forms.Label();
this.panel2 = new System.Windows.Forms.Panel();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.panel3 = new System.Windows.Forms.Panel();
this.textBox2 = new System.Windows.Forms.TextBox();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.panel3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).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.button1);
this.groupBox1.Location = new System.Drawing.Point(13, 13);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(784, 55);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "操作";
//
// button1
//
this.button1.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.button1.Location = new System.Drawing.Point(678, 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);
//
// panel1
//
this.panel1.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.panel1.BackColor = System.Drawing.SystemColors.Control;
this.panel1.Location = new System.Drawing.Point(13, 84);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(589, 590);
this.panel1.TabIndex = 1;
this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
this.panel1.Resize += new System.EventHandler(this.panel1_Resize);
//
// groupBox2
//
this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.groupBox2.Controls.Add(this.comboBox1);
this.groupBox2.Controls.Add(this.label4);
this.groupBox2.Controls.Add(this.panel2);
this.groupBox2.Controls.Add(this.label3);
this.groupBox2.Controls.Add(this.label2);
this.groupBox2.Controls.Add(this.textBox1);
this.groupBox2.Controls.Add(this.label1);
this.groupBox2.Location = new System.Drawing.Point(608, 84);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(189, 186);
this.groupBox2.TabIndex = 2;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "设置";
//
// comboBox1
//
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(61, 124);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(110, 20);
this.comboBox1.TabIndex = 6;
this.comboBox1.SelectionChangeCommitted += new System.EventHandler(this.comboBox1_SelectionChangeCommitted);
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(-2, 127);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(65, 12);
this.label4.TabIndex = 5;
this.label4.Text = "图片数量:";
//
// panel2
//
this.panel2.BackColor = System.Drawing.Color.Red;
this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel2.Location = new System.Drawing.Point(61, 75);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(110, 20);
this.panel2.TabIndex = 4;
this.panel2.Click += new System.EventHandler(this.panel2_Click);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(-2, 79);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(65, 12);
this.label3.TabIndex = 3;
this.label3.Text = "分栏颜色:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(142, 28);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(29, 12);
this.label2.TabIndex = 2;
this.label2.Text = "像素";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(61, 25);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(75, 21);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "0";
this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(-2, 28);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(65, 12);
this.label1.TabIndex = 0;
this.label1.Text = "图片间距:";
//
// groupBox3
//
this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.groupBox3.Controls.Add(this.checkBox1);
this.groupBox3.Controls.Add(this.panel3);
this.groupBox3.Location = new System.Drawing.Point(608, 270);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(189, 213);
this.groupBox3.TabIndex = 3;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "缩略图";
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Location = new System.Drawing.Point(8, 182);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(72, 16);
this.checkBox1.TabIndex = 1;
this.checkBox1.Text = "同步方式";
this.checkBox1.UseVisualStyleBackColor = true;
//
// panel3
//
this.panel3.Controls.Add(this.textBox2);
this.panel3.Controls.Add(this.pictureBox1);
this.panel3.Location = new System.Drawing.Point(8, 20);
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(163, 147);
this.panel3.TabIndex = 0;
//
// textBox2
//
this.textBox2.BackColor = System.Drawing.SystemColors.Control;
this.textBox2.Location = new System.Drawing.Point(40, 123);
this.textBox2.Name = "textBox2";
this.textBox2.ReadOnly = true;
this.textBox2.Size = new System.Drawing.Size(88, 21);
this.textBox2.TabIndex = 1;
this.textBox2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(162, 122);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);
//
// ColumnsShowDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
this.ClientSize = new System.Drawing.Size(809, 686);
this.Controls.Add(this.groupBox3);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.panel1);
this.Controls.Add(this.groupBox1);
this.MinimizeBox = false;
this.Name = "ColumnsShowDialog";
this.Text = "分栏显示:";
this.Controls.SetChildIndex(this.groupBox1, 0);
this.Controls.SetChildIndex(this.panel1, 0);
this.Controls.SetChildIndex(this.groupBox2, 0);
this.Controls.SetChildIndex(this.groupBox3, 0);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.groupBox3.ResumeLayout(false);
this.groupBox3.PerformLayout();
this.panel3.ResumeLayout(false);
this.panel3.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
}
///
/// 绑定其他数据
///
private void InitializeControlData()
{
//图片数量下拉菜单绑定
this.comboBox1.DataSource = imgCount;
this.comboBox1.SelectedIndex = 2;
//调色板
this.colorsForm = new ColorsForm();
this.colorsForm.StartPosition = FormStartPosition.CenterScreen;
this.colorsForm.UserPrimaryColorChanged += new ColorEventHandler(this.colorsFormUserPrimaryColorChanged);
}
///
/// 下拉菜单选项改变
///
///
///
private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
{
InitializeColControls();
this.panel1.Refresh();
lastPoint.X = 0;
lastPoint.Y = 0;
refreshRectangle();
}
///
/// 选中控件的边框
///
///
///
private void panel1_Paint(object sender, PaintEventArgs e)
{
Pen borderPen = new Pen(Color.Red, 5);//默认红色
for (int i = 0; i < listColControl.Count; i++)
{
if (listColControl[i].isSelect)
{
e.Graphics.DrawRectangle(borderPen, listColControl[i].Location.X - 2, listColControl[i].Location.Y - 2,
listColControl[i].Size.Width + 2, listColControl[i].Size.Height + 2);
}
}
borderPen.Dispose();
}
///
/// textbox限制输入数字
///
///
///
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
char kc = e.KeyChar;
if ((kc < 48 || kc > 57) && kc != 8 && kc != 46)
e.Handled = true;
if (kc == 46) //小数点
{
if (this.textBox1.Text.Length <= 0)
e.Handled = true; //小数点不能在第一位
else
{
float f;
float oldf;
bool b1 = false, b2 = false;
b1 = float.TryParse(this.textBox1.Text, out oldf);
b2 = float.TryParse(this.textBox1.Text + e.KeyChar.ToString(), out f);
if (b2 == false)
{
if (b1 == true)
e.Handled = true;
else
e.Handled = false;
}
}
}
}
private void colorsFormUserPrimaryColorChanged(object sender, ColorEventArgs ce)
{
}
///
/// 缩略图的鼠标按下事件
///
///
///
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
lastPoint.X = e.X;
lastPoint.Y = e.Y;
//是否平移
if (zoomRect.Contains(e.Location) && !new Rectangle((int)(zoomRect.Right - 3), (int)(zoomRect.Bottom - 3), 7, 7).Contains(e.Location))
{
isSelected = true;
}
else
{
isSelected = false;
}
//是否缩放
if (new Rectangle((int)(zoomRect.Right - 3), (int)(zoomRect.Bottom - 3), 7, 7).Contains(e.Location))
{
isResized = true;
}
else
{
isResized = false;
}
}
///
/// 缩略图的鼠标拖动事件
///
///
///
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
this.pictureBox1.Cursor = Cursors.Default;
if (zoomRect != null)
{
if (zoomRect.Contains(e.Location) && !new Rectangle((int)(zoomRect.Right - 3), (int)(zoomRect.Bottom - 3), 7, 7).Contains(e.Location))
{
this.pictureBox1.Cursor = Cursors.SizeAll;
}
if (new Rectangle((int)(zoomRect.Right - 3), (int)(zoomRect.Bottom - 3), 7, 7).Contains(e.Location))
{
this.pictureBox1.Cursor = Cursors.SizeNWSE;
}
}
if (e.Button != MouseButtons.Left)
return;
//拖拽
if (zoomRect != null && isSelected)
{
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 (newColtrol != null && newColtrol.isSelect)
{
Point scPoint = newColtrol.workspaceWindow.PanelScrollPosition;
this.newBitmap = newColtrol.workspaceWindow.CompositionSurface.CreateAliasedBitmap();
double scRatioWidth = imageRect.Width / (newBitmap.Width * newColtrol.workspaceWindow.ScaleRatio);
double scRatioHeight = imageRect.Height / (newBitmap.Height * newColtrol.workspaceWindow.ScaleRatio);
double scrollDx = dx / scRatioWidth;
double scrollDy = dy / scRatioHeight;
Point newScPoint = new Point(scPoint.X + Convert.ToInt32(Math.Round(scrollDx)), scPoint.Y + Convert.ToInt32(Math.Round(scrollDy)));
//是否同步
if (this.checkBox1.Checked)
{
for (int i = 0; i < imgCount[this.comboBox1.SelectedIndex]; i++)
{
if (listColControl[i].workspaceWindow.CompositionSurface != null)
{
listColControl[i].workspaceWindow.PanelScrollPosition = newScPoint;
}
}
}
else
{
newColtrol.workspaceWindow.PanelScrollPosition = newScPoint;
}
}
}
//放大缩小
if (zoomRect != null && isResized)
{
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;
//偏移量取横坐标与纵坐标中绝对值大的
int delta = dx;
if (Math.Abs(dy) > Math.Abs(dx))
delta = dy;
Size size = newColtrol.workspaceWindow.panel.ClientSize;//document尺寸
double ratio = newColtrol.workspaceWindow.ScaleRatio;//缩放比
this.newBitmap = newColtrol.workspaceWindow.CompositionSurface.CreateAliasedBitmap();
double winAspectRatio = (double)size.Width / (double)size.Height;//窗口宽高比
double imgAspectRatio = (double)(imageRect.Width - (zoomRect.X - imageRect.X)) / (double)(imageRect.Height - (zoomRect.Y - imageRect.Y));//最大红框宽高比
//计算临界点红框宽与高
int minWidth = 0;
int minHeight = 0;
if (winAspectRatio < imgAspectRatio)
{
minHeight = imageRect.Height - (zoomRect.Y - imageRect.Y);
minWidth = (int)(minHeight * winAspectRatio);
}
else
{
minWidth = imageRect.Width - (zoomRect.X - imageRect.X);
minHeight = (int)(minWidth / winAspectRatio);
}
//int minWidth = (int)((imageRect.Height - (zoomRect.Y-imageRect.Y)) * winAspectRatio);// 高度与最大高度相等时,缩略图中红框最小宽度
//int minHeight = (int)((imageRect.Width - (zoomRect.X - imageRect.X)) / winAspectRatio);// 宽度与最大宽度相等时,缩略图中红框最小高度
double newScaleRatio = 0;//重新计算缩放率
double criticalRatio = 0; //临界值缩放率
double newScPointX = 0;//计算后新的滚动条横坐标
double newScPointY = 0;//计算后新的滚动条纵坐标
if (winAspectRatio <= imgAspectRatio)
{
criticalRatio = (double)(size.Width) / (double)(this.newBitmap.Width);
}
else
{
criticalRatio = (double)(size.Height) / (double)(this.newBitmap.Height);
}
////图片缩放后的宽和高都小于document窗口尺寸
//if (size.Width > this.newBitmap.Width * ratio && size.Height > this.newBitmap.Height * ratio)
//{
newColtrol.workspaceWindow.ZoomBasis = ZoomBasis.ScaleFactor;//修改缩放模式
//只修改缩放比,不改变缩略图矩形框尺寸
ratio += (-delta / 100d);
if (ratio < 0.01)
ratio = 0.01;
//是否同步
if (this.checkBox1.Checked)
{
for (int i = 0; i < imgCount[this.comboBox1.SelectedIndex]; i++)
{
if (listColControl[i].workspaceWindow.CompositionSurface != null)
{
if (!listColControl[i].isSelect)
{
continue;
}
else
{
if (winAspectRatio < imgAspectRatio)
{
if (zoomRect.Width > minWidth)
{
zoomRect.Height = minHeight;
}
else
{
zoomRect.Height += dy;
}
//限制最小矩形框
if (zoomRect.Height < 3)
{
zoomRect.Height = 3;
zoomRect.Width = (int)(zoomRect.Height * winAspectRatio);
}
if (zoomRect.Height > 1 && zoomRect.Height < minHeight)
{
zoomRect.Width = (int)(zoomRect.Height * winAspectRatio);
}
if (zoomRect.Height >= minHeight)
{
zoomRect.Height = minHeight;
if (zoomRect.X == imageRect.X && zoomRect.Y == imageRect.Y)
{
zoomRect.Width += dx;
}
else
{
zoomRect.Width = minWidth;
}
if (zoomRect.Width < minWidth)
{
zoomRect.Width = minWidth;
}
else
{
zoomRect.Height = minHeight;
}
}
if (zoomRect.Width > (imageRect.Width - zoomRect.X))
{
zoomRect.Width = imageRect.Width - zoomRect.X;
}
}
else
{
if (zoomRect.Height > minHeight)
{
zoomRect.Width = minWidth;
}
else
{
zoomRect.Width += dx;
}
//限制最小矩形框
if (zoomRect.Width < 3)
{
zoomRect.Width = 3;
zoomRect.Height = (int)(zoomRect.Height / winAspectRatio);
}
if (zoomRect.Width > 1 && zoomRect.Width < imageRect.Width)
{
zoomRect.Height = (int)(zoomRect.Width / winAspectRatio);
}
if (zoomRect.Width >= minWidth)
{
zoomRect.Width = minWidth;
if (zoomRect.X == imageRect.X && zoomRect.Y == imageRect.Y)
{
zoomRect.Height += dy; ;
}
else
{
zoomRect.Height = minHeight;
}
if (zoomRect.Height < minHeight)
{
zoomRect.Height = minHeight;
}
else
{
zoomRect.Width = minWidth;
}
}
if (zoomRect.Height > (imageRect.Height - zoomRect.Y))
{
zoomRect.Height = imageRect.Height - zoomRect.Y;
}
}
double zoomRectWH = (double)zoomRect.Width / (double)zoomRect.Height;
widthRatio = zoomRect.Width / (imageRect.Width * 1d);
if (widthRatio > 1)
widthRatio = 1;
heightRatio = zoomRect.Height / (imageRect.Height * 1d);
if (heightRatio > 1)
heightRatio = 1;
if (zoomRectWH < winAspectRatio)
{
newScaleRatio = Math.Round(size.Height / heightRatio / newBitmap.Height, 10);//重新计算缩放比
if (newScaleRatio < 0.01)
newScaleRatio = 0.01;
}
else
{
newScaleRatio = Math.Round(size.Width / widthRatio / newBitmap.Width, 10);//重新计算缩放比
if (newScaleRatio < 0.01)
newScaleRatio = 0.01;
}
double imgRatio = (double)newBitmap.Width * newScaleRatio / (double)imageRect.Width;//缩放图与缩略图比率
newScPointX = (zoomRect.X - imageRect.X) * imgRatio;//新的X轴滚动条位置
newScPointY = (zoomRect.Y - imageRect.Y) * imgRatio;//新的Y轴滚动条位置
this.pictureBox1.Refresh();
if (newScaleRatio <= criticalRatio)
{
newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(criticalRatio);
newColtrol.workspaceWindow.Refresh();
}
else
{
newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(newScaleRatio);
newColtrol.workspaceWindow.Refresh();
}
newColtrol.workspaceWindow.PanelScrollPosition = new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY));
}
}
}
for (int i = 0; i < imgCount[this.comboBox1.SelectedIndex]; i++)
{
if (listColControl[i].workspaceWindow.CompositionSurface != null)
{
if (listColControl[i].isSelect)
{
continue;
}
else
{
if (listColControl[i].workspaceWindow.ZoomBasis != ZoomBasis.ScaleFactor)
listColControl[i].workspaceWindow.ZoomBasis = ZoomBasis.ScaleFactor;
listColControl[i].workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(newScaleRatio);
listColControl[i].workspaceWindow.Refresh();
}
}
}
}
else
{
if (winAspectRatio < imgAspectRatio)
{
if (zoomRect.Width > minWidth)
{
zoomRect.Height = minHeight;
}
else
{
zoomRect.Height += dy;
}
//限制最小矩形框
if (zoomRect.Height < 3)
{
zoomRect.Height = 3;
zoomRect.Width = (int)(zoomRect.Height * winAspectRatio);
}
if (zoomRect.Height > 1 && zoomRect.Height < minHeight)
{
zoomRect.Width = (int)(zoomRect.Height * winAspectRatio);
}
if (zoomRect.Height >= minHeight)
{
zoomRect.Height = minHeight;
if (zoomRect.X == imageRect.X && zoomRect.Y == imageRect.Y)
{
zoomRect.Width += dx;
}
else
{
zoomRect.Width = minWidth;
}
if (zoomRect.Width < minWidth)
{
zoomRect.Width = minWidth;
}
else
{
zoomRect.Height = minHeight;
}
}
if (zoomRect.Width > (imageRect.Width - zoomRect.X))
{
zoomRect.Width = imageRect.Width - zoomRect.X;
}
}
else
{
if (zoomRect.Height > minHeight)
{
zoomRect.Width = minWidth;
}
else
{
zoomRect.Width += dx;
}
//限制最小矩形框
if (zoomRect.Width < 3)
{
zoomRect.Width = 3;
zoomRect.Height = (int)(zoomRect.Height / winAspectRatio);
}
if (zoomRect.Width > 1 && zoomRect.Width < imageRect.Width)
{
zoomRect.Height = (int)(zoomRect.Width / winAspectRatio);
}
if (zoomRect.Width >= minWidth)
{
zoomRect.Width = minWidth;
if (zoomRect.X == imageRect.X && zoomRect.Y == imageRect.Y)
{
zoomRect.Height += dy;;
}
else
{
zoomRect.Height = minHeight;
}
if (zoomRect.Height < minHeight)
{
zoomRect.Height = minHeight;
}
else
{
zoomRect.Width = minWidth;
}
}
if (zoomRect.Height > (imageRect.Height - zoomRect.Y))
{
zoomRect.Height = imageRect.Height - zoomRect.Y;
}
}
//}
double zoomRectWH = (double)zoomRect.Width / (double)zoomRect.Height;
widthRatio = zoomRect.Width / (imageRect.Width * 1d);
if (widthRatio > 1)
widthRatio = 1;
heightRatio = zoomRect.Height / (imageRect.Height * 1d);
if (heightRatio > 1)
heightRatio = 1;
if (zoomRectWH < winAspectRatio)
{
newScaleRatio = Math.Round(size.Height / heightRatio / newBitmap.Height, 10);//重新计算缩放比
if (newScaleRatio < 0.01)
newScaleRatio = 0.01;
}
else
{
newScaleRatio = Math.Round(size.Width / widthRatio / newBitmap.Width, 10);//重新计算缩放比
if (newScaleRatio < 0.01)
newScaleRatio = 0.01;
}
double imgRatio = (double)newBitmap.Width * newScaleRatio / (double)imageRect.Width;//缩放图与缩略图比率
newScPointX = (zoomRect.X - imageRect.X) * imgRatio;//新的X轴滚动条位置
newScPointY = (zoomRect.Y - imageRect.Y) * imgRatio;//新的Y轴滚动条位置
this.pictureBox1.Refresh();
if (newScaleRatio <= criticalRatio)
{
newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(criticalRatio);
newColtrol.workspaceWindow.Refresh();
}
else
{
newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(newScaleRatio);
newColtrol.workspaceWindow.Refresh();
}
newColtrol.workspaceWindow.PanelScrollPosition = new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY));
}
getRatioBetweenPanelWindowAndBitmap(newColtrol);
this.textBox2.Text = Math.Round(newColtrol.workspaceWindow.ScaleFactor.Ratio * 100) + "%";
this.textBox2.Refresh();
//}
//else
//{
// double aspectRatio = size.Width / (size.Height * 1d);//宽高比
// int maxResizedWidth = imageRect.Right - zoomRect.Right;//正向最大拖动宽度
// int maxResizedHeigth = imageRect.Bottom - zoomRect.Bottom;//正向最大拖动高度
// int maxRectWidth = maxResizedWidth + zoomRect.Width;//小矩形可放大到的最大宽度
// int maxRectHeight = maxResizedHeigth + zoomRect.Height;//小矩形可放大到的最大高度
// double newScaleRatio = 0;//计算后新的缩放比
// double newScPointX = 0;//计算后新的滚动条横坐标
// double newScPointY = 0;//计算后新的滚动条纵坐标
// double scRatioWidth = 0;
// double scRatioHeight = 0;
// //图片缩放后只有宽小于ducument窗口尺寸
// if (size.Width > this.newBitmap.Width * ratio && size.Height <= this.newBitmap.Height * ratio)
// {
// int minHeight = (int)Math.Round(imageRect.Width / aspectRatio);//矩形框可拖动的最小高度
// double temporaryRatio = 0;
// zoomRect.Height += delta;
// if (zoomRect.Height > maxRectHeight)
// {
// zoomRect.Height = maxRectHeight;
// //矩形框的起始点不在缩略图的起始点上时,高度达到默认可变的最大值后,同时修改纵坐标和高度
// if (maxRectHeight < imageRect.Height)
// {
// zoomRect.Y -= delta;
// if (zoomRect.Y < imageRect.Y)
// zoomRect.Y = imageRect.Y;
// zoomRect.Height += delta;
// if (zoomRect.Height > imageRect.Height)
// zoomRect.Height = imageRect.Height;
// this.pictureBox1.Refresh();
// newScaleRatio = Math.Round(size.Height / heightRatio / this.newBitmap.Height, 2);//重新计算缩放比
// if (newScaleRatio < 0.01)
// newScaleRatio = 0.01;
// //重新计算滚轮所需比例
// scRatioWidth = imageRect.Width / (newBitmap.Width * newScaleRatio);
// scRatioHeight = imageRect.Height / (newBitmap.Height * newScaleRatio);
// //重新计算document的滚动条横坐标与纵坐标
// newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth;
// newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight;
// //是否同步
// if (this.checkBox1.Checked)
// {
// for (int i = 0; i < imgCount[this.comboBox1.SelectedIndex]; i++)
// {
// if (listColControl[i].workspaceWindow.CompositionSurface != null)
// {
// if (listColControl[i].workspaceWindow.ZoomBasis != ZoomBasis.ScaleFactor)
// listColControl[i].workspaceWindow.ZoomBasis = ZoomBasis.ScaleFactor;
// listColControl[i].workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(ratio);
// listColControl[i].workspaceWindow.PanelScrollPosition = new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY));
// listColControl[i].workspaceWindow.Refresh();
// }
// }
// }
// else
// {
// if (size.Height == this.newBitmap.Height * ratio)
// {
// temporaryRatio = ratio;
// }
// if (size.Height >= this.newBitmap.Height * ratio)
// {
// newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(temporaryRatio);
// }
// else
// {
// newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(ratio);
// }
// newColtrol.workspaceWindow.PanelScrollPosition = new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY));
// newColtrol.workspaceWindow.Refresh();
// }
// getRatioBetweenPanelWindowAndBitmap(newColtrol);
// this.textBox2.Text = Math.Round(newColtrol.workspaceWindow.ScaleFactor.Ratio * 100) + "%";
// this.textBox2.Refresh();
// return;
// }
// //高度达到极限,只改变缩放比
// this.pictureBox1.Refresh();
// ratio += (-delta / 100d);
// if (ratio < 0.01)
// ratio = 0.01;
// //是否同步
// if (this.checkBox1.Checked)
// {
// for (int i = 0; i < imgCount[this.comboBox1.SelectedIndex]; i++)
// {
// if (listColControl[i].workspaceWindow.CompositionSurface != null)
// {
// if (listColControl[i].workspaceWindow.ZoomBasis != ZoomBasis.ScaleFactor)
// listColControl[i].workspaceWindow.ZoomBasis = ZoomBasis.ScaleFactor;
// listColControl[i].workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(ratio);
// listColControl[i].workspaceWindow.Refresh();
// }
// }
// }
// else
// {
// if (size.Height == this.newBitmap.Height * ratio)
// {
// temporaryRatio = ratio;
// }
// if (size.Height >= this.newBitmap.Height * ratio)
// {
// newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(temporaryRatio);
// }
// else
// {
// newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(ratio);
// }
// //newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(ratio);
// newColtrol.workspaceWindow.Refresh();
// }
// return;
// }
// if (zoomRect.Height < minHeight)
// zoomRect.Height = minHeight;
// this.pictureBox1.Refresh();
// heightRatio = zoomRect.Height / (imageRect.Height * 1d);
// if (heightRatio > 1)
// heightRatio = 1;
// newScaleRatio = Math.Round(size.Height / heightRatio / this.newBitmap.Height, 2);//重新计算缩放比
// }
// //图片缩放后只有高小于ducument窗口尺寸
// if (size.Width <= this.newBitmap.Width * ratio && size.Height >= this.newBitmap.Height * ratio)
// {
// int minWidth = (int)Math.Round(zoomRect.Height * aspectRatio);//矩形框可拖动的最小宽度
// double temporaryRatio = 0;
// zoomRect.Width += delta;
// if (zoomRect.Width > maxRectWidth)
// {
// zoomRect.Width = maxRectWidth;
// //矩形框的起始点不在缩略图的起始点上时,宽度达到默认可变的最大值后,同时修改横坐标和宽度
// if (maxRectWidth < imageRect.Width)
// {
// zoomRect.X -= delta;
// if (zoomRect.X < imageRect.X)
// zoomRect.X = imageRect.X;
// zoomRect.Width += delta;
// if (zoomRect.Width > imageRect.Width)
// zoomRect.Width = imageRect.Width;
// this.pictureBox1.Refresh();
// newScaleRatio = Math.Round(size.Width / widthRatio / this.newBitmap.Width, 2);//重新计算缩放比
// if (newScaleRatio < 0.01)
// newScaleRatio = 0.01;
// //重新计算滚轮所需比例
// scRatioWidth = imageRect.Width / (newBitmap.Width * newScaleRatio);
// scRatioHeight = imageRect.Height / (newBitmap.Height * newScaleRatio);
// //重新计算document的滚动条横坐标与纵坐标
// newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth;
// newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight;
// //是否同步
// if (this.checkBox1.Checked)
// {
// for (int i = 0; i < imgCount[this.comboBox1.SelectedIndex]; i++)
// {
// if (listColControl[i].workspaceWindow.CompositionSurface != null)
// {
// if (listColControl[i].workspaceWindow.ZoomBasis != ZoomBasis.ScaleFactor)
// listColControl[i].workspaceWindow.ZoomBasis = ZoomBasis.ScaleFactor;
// listColControl[i].workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(newScaleRatio);
// listColControl[i].workspaceWindow.PanelScrollPosition = new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY));
// listColControl[i].workspaceWindow.Refresh();
// }
// }
// }
// else
// {
// if (size.Width == this.newBitmap.Width * ratio)
// {
// temporaryRatio = ratio;
// }
// if (size.Width >= this.newBitmap.Width * ratio)
// {
// newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(temporaryRatio);
// }
// else
// {
// newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(ratio);
// }
// //newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(newScaleRatio);
// newColtrol.workspaceWindow.PanelScrollPosition = new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY));
// newColtrol.workspaceWindow.Refresh();
// }
// getRatioBetweenPanelWindowAndBitmap(newColtrol);
// this.textBox2.Text = Math.Round(newColtrol.workspaceWindow.ScaleFactor.Ratio * 100) + "%";
// this.textBox2.Refresh();
// return;
// }
// //宽度达到极限,改变缩放比
// this.pictureBox1.Refresh();
// ratio += (-delta / 100d);
// if (ratio < 0.01)
// ratio = 0.01;
// //是否同步
// if (this.checkBox1.Checked)
// {
// for (int i = 0; i < imgCount[this.comboBox1.SelectedIndex]; i++)
// {
// if (listColControl[i].workspaceWindow.CompositionSurface != null)
// {
// if (listColControl[i].workspaceWindow.ZoomBasis != ZoomBasis.ScaleFactor)
// listColControl[i].workspaceWindow.ZoomBasis = ZoomBasis.ScaleFactor;
// listColControl[i].workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(ratio);
// listColControl[i].workspaceWindow.Refresh();
// }
// }
// }
// else
// {
// if (size.Width == this.newBitmap.Width * ratio)
// {
// temporaryRatio = ratio;
// }
// if (size.Width >= this.newBitmap.Width * ratio)
// {
// newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(temporaryRatio);
// }
// else
// {
// newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(ratio);
// }
// //newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(ratio);
// newColtrol.workspaceWindow.Refresh();
// }
// getRatioBetweenPanelWindowAndBitmap(newColtrol);
// this.textBox2.Text = Math.Round(newColtrol.workspaceWindow.ScaleFactor.Ratio * 100) + "%";
// this.textBox2.Refresh();
// return;
// }
// if (zoomRect.Width < minWidth)
// zoomRect.Width = minWidth;
// this.pictureBox1.Refresh();
// widthRatio = zoomRect.Width / (imageRect.Width * 1d);
// if (widthRatio > 1)
// widthRatio = 1;
// newScaleRatio = Math.Round(size.Width / widthRatio / this.newBitmap.Width, 2);//重新计算缩放比
// }
// //图片缩放后的宽和高都不小于document窗体尺寸
// if (size.Width <= this.newBitmap.Width * ratio && size.Height <= this.newBitmap.Height * ratio)
// {
// if (maxResizedWidth < maxResizedHeigth)
// {
// zoomRect.Width += delta;
// if (zoomRect.Width > maxRectWidth)
// {
// zoomRect.Width = maxRectWidth;
// //矩形框的宽度与缩略图宽度相同时才可改变高度并调整缩放比
// if (zoomRect.Width >= imageRect.Width)
// {
// zoomRect.Height += delta;
// this.pictureBox1.Refresh();
// heightRatio = zoomRect.Height / (imageRect.Height * 1d);
// if (heightRatio > 1)
// heightRatio = 1;
// newScaleRatio = Math.Round(size.Height / heightRatio / newBitmap.Height, 2);//重新计算缩放比
// if (newScaleRatio < 0.01)
// newScaleRatio = 0.01;
// //重新计算滚轮所需比例
// scRatioWidth = imageRect.Width / (newBitmap.Width * newScaleRatio);
// scRatioHeight = imageRect.Height / (newBitmap.Height * newScaleRatio);
// //重新计算document的滚动条横坐标与纵坐标
// newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth;
// newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight;
// //是否同步
// if (this.checkBox1.Checked)
// {
// for (int i = 0; i < imgCount[this.comboBox1.SelectedIndex]; i++)
// {
// if (listColControl[i].workspaceWindow.CompositionSurface != null)
// {
// if (listColControl[i].workspaceWindow.ZoomBasis != ZoomBasis.ScaleFactor)
// listColControl[i].workspaceWindow.ZoomBasis = ZoomBasis.ScaleFactor;
// listColControl[i].workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(newScaleRatio);
// listColControl[i].workspaceWindow.PanelScrollPosition = new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY));
// listColControl[i].workspaceWindow.Refresh();
// }
// }
// }
// else
// {
// newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(newScaleRatio);
// newColtrol.workspaceWindow.PanelScrollPosition = new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY));
// newColtrol.workspaceWindow.Refresh();
// }
// getRatioBetweenPanelWindowAndBitmap(newColtrol);
// this.textBox2.Text = Math.Round(newColtrol.workspaceWindow.ScaleFactor.Ratio * 100) + "%";
// this.textBox2.Refresh();
// return;
// }
// }
// if (zoomRect.Width < minRectWidth)
// zoomRect.Width = minRectWidth;
// zoomRect.Height = (int)Math.Round(zoomRect.Width / aspectRatio);
// }
// else
// {
// zoomRect.Height += delta;
// if (zoomRect.Height > maxRectHeight)
// {
// zoomRect.Height = maxRectHeight;
// //矩形框的高度与缩略图高度相同时才可改变宽度并调整缩放比
// if (zoomRect.Height >= imageRect.Height)
// {
// zoomRect.Width += delta;
// this.pictureBox1.Refresh();
// widthRatio = zoomRect.Width / (imageRect.Width * 1d);
// if (widthRatio > 1)
// widthRatio = 1;
// newScaleRatio = Math.Round(size.Width / widthRatio / newBitmap.Width, 2);//重新计算缩放比
// if (newScaleRatio < 0.01)
// newScaleRatio = 0.01;
// //重新计算滚轮所需比例
// scRatioWidth = imageRect.Width / (newBitmap.Width * newScaleRatio);
// scRatioHeight = imageRect.Height / (newBitmap.Height * newScaleRatio);
// //重新计算document的滚动条横坐标与纵坐标
//newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth;
// newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight;
// //是否同步
// if (this.checkBox1.Checked)
// {
// for (int i = 0; i < imgCount[this.comboBox1.SelectedIndex]; i++)
// {
// if (listColControl[i].workspaceWindow.CompositionSurface != null)
// {
// if (listColControl[i].workspaceWindow.ZoomBasis != ZoomBasis.ScaleFactor)
// listColControl[i].workspaceWindow.ZoomBasis = ZoomBasis.ScaleFactor;
// listColControl[i].workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(newScaleRatio);
// listColControl[i].workspaceWindow.PanelScrollPosition = new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY));
// listColControl[i].workspaceWindow.Refresh();
// }
// }
// }
// else
// {
// newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(newScaleRatio);
// newColtrol.workspaceWindow.PanelScrollPosition = new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY));
// newColtrol.workspaceWindow.Refresh();
// }
// getRatioBetweenPanelWindowAndBitmap(newColtrol);
// this.textBox2.Text = Math.Round(newColtrol.workspaceWindow.ScaleFactor.Ratio * 100) + "%";
// this.textBox2.Refresh();
// return;
// }
// }
// if (zoomRect.Height < minRectHeight)
// zoomRect.Height = minRectHeight;
// zoomRect.Width = (int)Math.Round(zoomRect.Height * aspectRatio);
// }
// this.pictureBox1.Refresh();
// //重新计算比例
// widthRatio = zoomRect.Width / (imageRect.Width * 1d);
// if (widthRatio > 1)
// widthRatio = 1;
// heightRatio = zoomRect.Height / (imageRect.Height * 1d);
// if (heightRatio > 1)
// heightRatio = 1;
// //计算document的缩放比,宽和高的计算结果会有细微差异
// double scaleW = Math.Round(size.Width / widthRatio / newBitmap.Width, 2);
// double scaleH = Math.Round(size.Height / heightRatio / newBitmap.Height, 2);
// //取大的值作为新的缩放比?不确定
// if (scaleW >= scaleH)
// newScaleRatio = scaleW;
// else
// newScaleRatio = scaleH;
// }
// //重新计算滚轮所需比例
// scRatioWidth = imageRect.Width / (newBitmap.Width * newScaleRatio);
// scRatioHeight = imageRect.Height / (newBitmap.Height * newScaleRatio);
// //重新计算document的滚动条横坐标与纵坐标
// newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth;
// newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight;
// //是否同步
// if (this.checkBox1.Checked)
// {
// for (int i = 0; i < imgCount[this.comboBox1.SelectedIndex]; i++)
// {
// if (listColControl[i].workspaceWindow.CompositionSurface != null)
// {
// if (listColControl[i].workspaceWindow.ZoomBasis != ZoomBasis.ScaleFactor)
// listColControl[i].workspaceWindow.ZoomBasis = ZoomBasis.ScaleFactor;
// listColControl[i].workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(newScaleRatio);
// listColControl[i].workspaceWindow.PanelScrollPosition = new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY));
// listColControl[i].workspaceWindow.Refresh();
// }
// }
// }
// else
// {
// newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(newScaleRatio);
// newColtrol.workspaceWindow.PanelScrollPosition = new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY));
// newColtrol.workspaceWindow.Refresh();
// }
//}
getRatioBetweenPanelWindowAndBitmap(newColtrol);
this.textBox2.Text = Math.Round(newColtrol.workspaceWindow.ScaleFactor.Ratio * 100) + "%";
this.textBox2.Refresh();
}
}
private void panel2_Click(object sender, EventArgs e)
{
this.colorsForm.UserPrimaryColor = ColorBgra.FromColor(this.panel2.BackColor);
this.colorsForm.setSaveBtn_Click(new System.EventHandler(this.panel2Changed));
this.colorsForm.ShowDialog();
}
///
/// 合并并创建图片
///
///
///
private void button1_Click(object sender, EventArgs e)
{
Bitmap[] bitmaps = new Bitmap[imgCount[this.comboBox1.SelectedIndex]];
int[] oneHeight = new int[imgCount[this.comboBox1.SelectedIndex]];
for (int i = 0; i < imgCount[this.comboBox1.SelectedIndex]; i++)
{
if (this.listColControl[i].workspaceWindow.CompositionSurface != null)
{
Size size = this.listColControl[i].workspaceWindow.panel.ClientSize;
Bitmap compareBit = this.listColControl[i].workspaceWindow.CompositionSurface.CreateAliasedBitmap();
double compareRatio = this.listColControl[i].workspaceWindow.ScaleRatio;
if (compareBit.Width * compareRatio >= size.Width && compareBit.Height * compareRatio >= size.Height)
{
//bitmaps[i] = this.listColControl[i].workspaceWindow.GetClientRangePic();
//Rectangle rc = this.listColControl[i].workspaceWindow.panel.ClientRectangle;
//int width = (int)(this.listColControl[i].workspaceWindow.CompositionSurface.Width * compareRatio);
//int height = (int)(this.listColControl[i].workspaceWindow.CompositionSurface.Height * compareRatio);
//int x = (rc.Width < width) ? this.listColControl[i].workspaceWindow.panel.AutoScrollPosition.X : (rc.Width - width) / 2;
//int y = (rc.Height < height) ? this.listColControl[i].workspaceWindow.panel.AutoScrollPosition.Y : (rc.Height - height) / 2;
//DocumentView documentView = new DocumentView();
//if (this.listColControl[i].workspaceWindow.CompositionSurface.CreateAliasedBitmap() != null)
//{
// using (Surface doubleBuffer = documentView.GetDoubleBuffer(new Size((rc.Width < width) ? rc.Width : width, (rc.Height < height) ? rc.Height : height)))
// {
// using (RenderArgs renderArgs = new RenderArgs(doubleBuffer))
// {
// documentView.DrawArea(renderArgs, new Point((rc.Width < width) ? -x : 0, (rc.Height < height) ? -y : 0));
// bitmaps[i] = doubleBuffer.CreateAliasedBitmap();
// }
// }
//}
//bitmaps[i] = this.compositionSurface.CreateAliasedBitmap();
if (compareRatio < 1)
{
int x = Math.Abs((int)(this.listColControl[i].workspaceWindow.panel.AutoScrollPosition.X / compareRatio));
int y = Math.Abs((int)(this.listColControl[i].workspaceWindow.panel.AutoScrollPosition.Y / compareRatio));
int width = (int)(size.Width / compareRatio);
int height = (int)(size.Height / compareRatio);
bitmaps[i] = CaptureImage(compareBit, x, y, width, height);
}
else
{
Bitmap bmp = new Bitmap(size.Width, size.Height);
this.listColControl[i].workspaceWindow.panel.DrawToBitmap(bmp, this.listColControl[i].workspaceWindow.panel.ClientRectangle);
bitmaps[i] = bmp;
}
}
else
{
//bitmaps[i] = GetScaleBitmap(compareBit, compareRatio);//获得缩放后的原图
////截取显示区域对应的图片
//int newWidth = 0;
//if (bitmaps[i].Width <= size.Width)
// newWidth = bitmaps[i].Width;
//else
// newWidth = size.Width;
//int newHeight = 0;
//if (bitmaps[i].Height <= size.Height)
// newHeight = bitmaps[i].Height;
//else
// newHeight = size.Height;
//Point scPoint = this.listColControl[i].workspaceWindow.PanelScrollPosition;//滚轮位置
//Bitmap newCompareBit = new Bitmap(newWidth, newHeight);
//Graphics g = Graphics.FromImage(newCompareBit);
//g.Clear(Color.Black);
////设置画布的描绘质量
//g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
//g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
//g.DrawImage(bitmaps[i], new Rectangle(0, 0, newCompareBit.Width, newCompareBit.Height), scPoint.X, scPoint.Y, bitmaps[i].Width - scPoint.X, bitmaps[i].Height - scPoint.Y, GraphicsUnit.Pixel);
//g.Dispose();
bitmaps[i] = compareBit;
}
oneHeight[i] = bitmaps[i].Height;
}
}
int onePicHeight = oneHeight.Max();
Bitmap joinedBitmap = JoinBitmap(bitmaps, onePicHeight);
if (joinedBitmap != null)
{
OpenFileImpl(joinedBitmap);
this.Close();
}
else
{
MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text"));
}
}
///
/// 创建新图片
///
///
private void OpenFileImpl(Bitmap bitmap)
{
if (bitmap != null)
{
DocumentWorkspace dw = this.appWorkspace.AddNewDocumentWorkspace();
dw.Document = Document.FromImageMat(Camera.Tools.ToMat(bitmap));
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;
}
}
///
/// 拼接图片
///
///
///
///
///
private Bitmap JoinBitmap(Bitmap[] bitmaps, int onePicHeight)
{
if (bitmaps == null || onePicHeight <= 0)
return null;
Bitmap joinBitmap;
int[] everyRowWidth = new int[] { 0, 0, 0, 0 };
for (int i = 0; i < bitmaps.Count(); i++)
{
if (bitmaps[i] != null)
{
if (bitmaps[i].Height < onePicHeight)
{
bitmaps[i] = GetScaleBitmap(bitmaps[i], (double)onePicHeight / (double)bitmaps[i].Height);
}
}
}
switch (imgCount[this.comboBox1.SelectedIndex])
{
case 2:
int[] rowOneWidth2 = new int[] { bitmaps[0] == null ? 0 : bitmaps[0].Width };
int[] rowTwoWidth2 = new int[] { bitmaps[1] == null ? 0 : bitmaps[1].Width };
//每列的最大宽度集合
int[] maxLstWidth2 = new int[] { rowOneWidth2.Max(), rowTwoWidth2.Max() };
//获取最大宽度列,用来代替没有图片的列
int maxWidth2 = maxLstWidth2.Max();
if (rowOneWidth2.Max() == 0)
{
everyRowWidth[0] = maxWidth2;
}
else
{
everyRowWidth[0] = rowOneWidth2.Max();
}
if (rowTwoWidth2.Max() == 0)
{
everyRowWidth[1] = maxWidth2;
}
else
{
everyRowWidth[1] = rowTwoWidth2.Max();
}
imgWidth = everyRowWidth.Sum() + int.Parse(this.textBox1.Text);
imgHeight = onePicHeight;
break;
case 3:
int[] rowOneWidth3 = new int[] { bitmaps[0] == null ? 0 : bitmaps[0].Width };
int[] rowTwoWidth3 = new int[] { bitmaps[1] == null ? 0 : bitmaps[1].Width };
int[] rowThreeWidth3 = new int[] { bitmaps[2] == null ? 0 : bitmaps[2].Width };
//每列的最大宽度集合
int[] maxLstWidth3 = new int[] { rowOneWidth3.Max(), rowTwoWidth3.Max(), rowThreeWidth3.Max() };
//获取最大宽度列,用来代替没有图片的列
int maxWidth3 = maxLstWidth3.Max();
int[] Width3 = new int[3];
if (rowOneWidth3.Max() == 0)
{
everyRowWidth[0] = maxWidth3;
}
else
{
everyRowWidth[0] = rowOneWidth3.Max();
}
if (rowTwoWidth3.Max() == 0)
{
everyRowWidth[1] = maxWidth3;
}
else
{
everyRowWidth[1] = rowTwoWidth3.Max();
}
if (rowThreeWidth3.Max() == 0)
{
everyRowWidth[2] = maxWidth3;
}
else
{
everyRowWidth[2] = rowThreeWidth3.Max();
}
imgWidth = everyRowWidth.Sum() + int.Parse(this.textBox1.Text) * 2;
imgHeight = onePicHeight;
break;
case 4:
int[] rowOneWidth4 = new int[] { bitmaps[0] == null ? 0 : bitmaps[0].Width, bitmaps[2] == null ? 0 : bitmaps[2].Width };
int[] rowTwoWidth4 = new int[] { bitmaps[1] == null ? 0 : bitmaps[1].Width, bitmaps[3] == null ? 0 : bitmaps[3].Width };
//每列的最大宽度集合
int[] maxLstWidth4 = new int[] { rowOneWidth4.Max(), rowTwoWidth4.Max() };
//获取最大宽度列,用来代替没有图片的列
int maxWidth4 = maxLstWidth4.Max();
if (rowOneWidth4.Max() == 0)
{
everyRowWidth[0] = maxWidth4;
}
else
{
everyRowWidth[0] = rowOneWidth4.Max();
}
if (rowTwoWidth4.Max() == 0)
{
everyRowWidth[1] = maxWidth4;
}
else
{
everyRowWidth[1] = rowTwoWidth4.Max();
}
imgWidth = everyRowWidth.Sum() + int.Parse(this.textBox1.Text);
imgHeight = onePicHeight * 2 + int.Parse(this.textBox1.Text);
break;
case 6:
int[] rowOneWidth6 = new int[] { bitmaps[0] == null ? 0 : bitmaps[0].Width, bitmaps[3] == null ? 0 : bitmaps[3].Width };
int[] rowTwoWidth6 = new int[] { bitmaps[1] == null ? 0 : bitmaps[1].Width, bitmaps[4] == null ? 0 : bitmaps[4].Width };
int[] rowThreeWidth6 = new int[] { bitmaps[2] == null ? 0 : bitmaps[2].Width, bitmaps[5] == null ? 0 : bitmaps[5].Width };
//每列的最大宽度集合
int[] maxLstWidth6 = new int[] { rowOneWidth6.Max(), rowTwoWidth6.Max(), rowThreeWidth6.Max() };
//获取最大宽度列,用来代替没有图片的列
int maxWidth6 = maxLstWidth6.Max();
int[] Width6 = new int[3];
if (rowOneWidth6.Max() == 0)
{
everyRowWidth[0] = maxWidth6;
}
else
{
everyRowWidth[0] = rowOneWidth6.Max();
}
if (rowTwoWidth6.Max() == 0)
{
everyRowWidth[1] = maxWidth6;
}
else
{
everyRowWidth[1] = rowTwoWidth6.Max();
}
if (rowThreeWidth6.Max() == 0)
{
everyRowWidth[2] = maxWidth6;
}
else
{
everyRowWidth[2] = rowThreeWidth6.Max();
}
imgWidth = everyRowWidth.Sum() + int.Parse(this.textBox1.Text) * 2;
imgHeight = onePicHeight * 2 + int.Parse(this.textBox1.Text);
break;
case 8:
int[] rowOneWidth8 = new int[] { bitmaps[0] == null ? 0 : bitmaps[0].Width, bitmaps[4] == null ? 0 : bitmaps[4].Width };
int[] rowTwoWidth8 = new int[] { bitmaps[1] == null ? 0 : bitmaps[1].Width, bitmaps[5] == null ? 0 : bitmaps[5].Width };
int[] rowThreeWidth8 = new int[] { bitmaps[2] == null ? 0 : bitmaps[2].Width, bitmaps[6] == null ? 0 : bitmaps[6].Width };
int[] rowFourWidth8 = new int[] { bitmaps[3] == null ? 0 : bitmaps[3].Width, bitmaps[7] == null ? 0 : bitmaps[7].Width };
//每列的最大宽度集合
int[] maxLstWidth8 = new int[] { rowOneWidth8.Max(), rowTwoWidth8.Max(), rowThreeWidth8.Max(), rowFourWidth8.Max() };
//获取最大宽度列,用来代替没有图片的列
int maxWidth8 = maxLstWidth8.Max();
int[] Width8 = new int[3];
if (rowOneWidth8.Max() == 0)
{
everyRowWidth[0] = maxWidth8;
}
else
{
everyRowWidth[0] = rowOneWidth8.Max();
}
if (rowTwoWidth8.Max() == 0)
{
everyRowWidth[1] = maxWidth8;
}
else
{
everyRowWidth[1] = rowTwoWidth8.Max();
}
if (rowThreeWidth8.Max() == 0)
{
everyRowWidth[2] = maxWidth8;
}
else
{
everyRowWidth[2] = rowThreeWidth8.Max();
}
if (rowFourWidth8.Max() == 0)
{
everyRowWidth[3] = maxWidth8;
}
else
{
everyRowWidth[3] = rowFourWidth8.Max();
}
imgWidth = everyRowWidth.Sum() + int.Parse(this.textBox1.Text) * 3;
imgHeight = onePicHeight * 2 + int.Parse(this.textBox1.Text);
break;
case 9:
int[] rowOneWidth9 = new int[] { bitmaps[0] == null ? 0 : bitmaps[0].Width, bitmaps[3] == null ? 0 : bitmaps[3].Width, bitmaps[6] == null ? 0 : bitmaps[6].Width };
int[] rowTwoWidth9 = new int[] { bitmaps[1] == null ? 0 : bitmaps[1].Width, bitmaps[4] == null ? 0 : bitmaps[4].Width, bitmaps[7] == null ? 0 : bitmaps[7].Width };
int[] rowThreeWidth9 = new int[] { bitmaps[2] == null ? 0 : bitmaps[2].Width, bitmaps[5] == null ? 0 : bitmaps[5].Width, bitmaps[8] == null ? 0 : bitmaps[8].Width };
//每列的最大宽度集合
int[] maxLstWidth9 = new int[] { rowOneWidth9.Max(), rowTwoWidth9.Max(), rowThreeWidth9.Max() };
//获取最大宽度列,用来代替没有图片的列
int maxWidth9 = maxLstWidth9.Max();
int[] Width9 = new int[3];
if (rowOneWidth9.Max() == 0)
{
everyRowWidth[0] = maxWidth9;
}
else
{
everyRowWidth[0] = rowOneWidth9.Max();
}
if (rowTwoWidth9.Max() == 0)
{
everyRowWidth[1] = maxWidth9;
}
else
{
everyRowWidth[1] = rowTwoWidth9.Max();
}
if (rowThreeWidth9.Max() == 0)
{
everyRowWidth[2] = maxWidth9;
}
else
{
everyRowWidth[2] = rowThreeWidth9.Max();
}
imgWidth = everyRowWidth.Sum() + int.Parse(this.textBox1.Text) * 2;
imgHeight = onePicHeight * 3 + int.Parse(this.textBox1.Text) * 2;
break;
}
if (imgWidth > 0 && imgHeight > 0)
{
joinBitmap = new Bitmap(imgWidth, imgHeight);
joinBitmap = JoinAllBitmap(joinBitmap, bitmaps, everyRowWidth, onePicHeight);
return joinBitmap;
}
else
{
return null;
}
}
///
/// 获取按比例缩放的图片
///
///
///
///
private Bitmap GetScaleBitmap(Bitmap bit, double ratio)
{
Bitmap destBitmap = new Bitmap(Convert.ToInt32(bit.Width * ratio), Convert.ToInt32(bit.Height * ratio));
Graphics g = Graphics.FromImage(destBitmap);
g.Clear(this.panel2.BackColor);
//设置画布的描绘质量
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.DrawImage(bit, new Rectangle(0, 0, destBitmap.Width, destBitmap.Height), 0, 0, bit.Width, bit.Height, GraphicsUnit.Pixel);
g.Dispose();
return destBitmap;
}
///
/// 把小图拼到一起
///
///
///
///
///
///
private Bitmap JoinAllBitmap(Bitmap bmp, Bitmap[] bitmaps, int[] everyRowWidth, int onePicHeight)
{
int imgCount = bitmaps.Count();
Graphics graph = Graphics.FromImage(bmp);
graph.FillRectangle(new SolidBrush(this.panel2.BackColor), 0, 0, imgWidth, imgHeight);
graph.DrawImage(bmp, imgWidth, imgHeight);
switch (imgCount)
{
case 2:
if (bitmaps[0] != null)
{
graph.DrawImage(bitmaps[0], 0, 0);
}
if (bitmaps[1] != null)
{
graph.DrawImage(bitmaps[1], everyRowWidth[0] + int.Parse(this.textBox1.Text), 0);
}
break;
case 3:
if (bitmaps[0] != null)
{
graph.DrawImage(bitmaps[0], 0, 0);
}
if (bitmaps[1] != null)
{
graph.DrawImage(bitmaps[1], everyRowWidth[0] + int.Parse(this.textBox1.Text), 0);
}
if (bitmaps[2] != null)
{
graph.DrawImage(bitmaps[2], everyRowWidth[0] + everyRowWidth[1] + int.Parse(this.textBox1.Text) * 2, 0);
}
break;
case 4:
if (bitmaps[0] != null)
{
graph.DrawImage(bitmaps[0], 0, 0);
}
if (bitmaps[1] != null)
{
graph.DrawImage(bitmaps[1], everyRowWidth[0] + int.Parse(this.textBox1.Text), 0);
}
if (bitmaps[2] != null)
{
graph.DrawImage(bitmaps[2], 0, onePicHeight + int.Parse(this.textBox1.Text));
}
if (bitmaps[3] != null)
{
graph.DrawImage(bitmaps[3], everyRowWidth[0] + int.Parse(this.textBox1.Text), onePicHeight + int.Parse(this.textBox1.Text));
}
break;
case 6:
if (bitmaps[0] != null)
{
graph.DrawImage(bitmaps[0], 0, 0);
}
if (bitmaps[1] != null)
{
graph.DrawImage(bitmaps[1], everyRowWidth[0] + int.Parse(this.textBox1.Text), 0);
}
if (bitmaps[2] != null)
{
graph.DrawImage(bitmaps[2], everyRowWidth[0] + everyRowWidth[1] + int.Parse(this.textBox1.Text) * 2, 0);
}
if (bitmaps[3] != null)
{
graph.DrawImage(bitmaps[3], 0, onePicHeight + int.Parse(this.textBox1.Text));
}
if (bitmaps[4] != null)
{
graph.DrawImage(bitmaps[4], everyRowWidth[0] + int.Parse(this.textBox1.Text), onePicHeight + int.Parse(this.textBox1.Text));
}
if (bitmaps[5] != null)
{
graph.DrawImage(bitmaps[5], everyRowWidth[0] + everyRowWidth[1] + int.Parse(this.textBox1.Text) * 2, onePicHeight + int.Parse(this.textBox1.Text));
}
break;
case 8:
if (bitmaps[0] != null)
{
graph.DrawImage(bitmaps[0], 0, 0);
}
if (bitmaps[1] != null)
{
graph.DrawImage(bitmaps[1], everyRowWidth[0] + int.Parse(this.textBox1.Text), 0);
}
if (bitmaps[2] != null)
{
graph.DrawImage(bitmaps[2], everyRowWidth[0] + everyRowWidth[1] + int.Parse(this.textBox1.Text) * 2, 0);
}
if (bitmaps[3] != null)
{
graph.DrawImage(bitmaps[3], everyRowWidth[0] + everyRowWidth[1] + everyRowWidth[2] + int.Parse(this.textBox1.Text) * 3, 0);
}
if (bitmaps[4] != null)
{
graph.DrawImage(bitmaps[4], 0, onePicHeight + int.Parse(this.textBox1.Text));
}
if (bitmaps[5] != null)
{
graph.DrawImage(bitmaps[5], everyRowWidth[0] + int.Parse(this.textBox1.Text), onePicHeight + int.Parse(this.textBox1.Text));
}
if (bitmaps[6] != null)
{
graph.DrawImage(bitmaps[6], everyRowWidth[0] + everyRowWidth[1] + int.Parse(this.textBox1.Text) * 2, onePicHeight + int.Parse(this.textBox1.Text));
}
if (bitmaps[7] != null)
{
graph.DrawImage(bitmaps[7], everyRowWidth[0] + everyRowWidth[1] + everyRowWidth[2] + int.Parse(this.textBox1.Text) * 3, onePicHeight + int.Parse(this.textBox1.Text));
}
break;
case 9:
if (bitmaps[0] != null)
{
graph.DrawImage(bitmaps[0], 0, 0);
}
if (bitmaps[1] != null)
{
graph.DrawImage(bitmaps[1], everyRowWidth[0] + int.Parse(this.textBox1.Text), 0);
}
if (bitmaps[2] != null)
{
graph.DrawImage(bitmaps[2], everyRowWidth[0] + everyRowWidth[1] + int.Parse(this.textBox1.Text) * 2, 0);
}
if (bitmaps[3] != null)
{
graph.DrawImage(bitmaps[3], 0, onePicHeight + int.Parse(this.textBox1.Text));
}
if (bitmaps[4] != null)
{
graph.DrawImage(bitmaps[4], everyRowWidth[0] + int.Parse(this.textBox1.Text), onePicHeight + int.Parse(this.textBox1.Text));
}
if (bitmaps[5] != null)
{
graph.DrawImage(bitmaps[5], everyRowWidth[0] + everyRowWidth[1] + int.Parse(this.textBox1.Text) * 2, onePicHeight + int.Parse(this.textBox1.Text));
}
if (bitmaps[6] != null)
{
graph.DrawImage(bitmaps[6], 0, onePicHeight * 2 + int.Parse(this.textBox1.Text) * 2);
}
if (bitmaps[7] != null)
{
graph.DrawImage(bitmaps[7], everyRowWidth[0] + int.Parse(this.textBox1.Text), onePicHeight * 2 + int.Parse(this.textBox1.Text) * 2);
}
if (bitmaps[8] != null)
{
graph.DrawImage(bitmaps[8], everyRowWidth[0] + everyRowWidth[1] + int.Parse(this.textBox1.Text) * 2, onePicHeight * 2 + int.Parse(this.textBox1.Text) * 2);
}
break;
}
return bmp;
}
private void panel2Changed(object sender, EventArgs e)
{
this.panel2.BackColor = this.colorsForm.UserPrimaryColor.ToColor();
this.colorsForm.Close();
}
///
/// 窗口大小改变
///
///
///
private void panel1_Resize(object sender, EventArgs e)
{
lastPoint.X = 0;
lastPoint.Y = 0;
RefreshColcontrol();
refreshRectangle();
}
///
/// 刷新picture的矩形框
///
private void refreshRectangle()
{
isFirst = true;
for (int i = 0; i < listColControl.Count; i++)
{
if (this.listColControl[i].isSelect == true)
{
newColtrol = this.listColControl[i];
break;
}
}
if (newColtrol != null && newColtrol.workspaceWindow.CompositionSurface != null)
{
getRatioBetweenPanelWindowAndBitmap(newColtrol);
this.pictureBox1.Refresh();
}
}
///
/// 通过document窗口与图片计算显示比例
///
///
private void getRatioBetweenPanelWindowAndBitmap(ColControl colControl)
{
Size size = colControl.workspaceWindow.panel.ClientSize;
newBitmap = colControl.workspaceWindow.CompositionSurface.CreateAliasedBitmap();
int width = size.Width;
int height = size.Height;
widthRatio = (double)width / ((double)newBitmap.Width * colControl.workspaceWindow.ScaleRatio);
if (widthRatio > 1)
{
widthRatio = 1;
}
heightRatio = (double)height / ((double)newBitmap.Height * colControl.workspaceWindow.ScaleRatio);
if (heightRatio > 1)
{
heightRatio = 1;
}
}
///
/// 点击图库按钮
///
///
///
private void colControlButton_Click(object sender, EventArgs e)
{
if (((Button)sender).Tag != null)
{
buttonNum = Convert.ToInt32(((Button)sender).Tag);
}
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();
}
}
}
///
/// 从图库选择待对照图片
///
///
///
private void inputMat_ValueChanged(object sender, EventArgs e)
{
if (sender is DocumentWorkspace)
{
this.newColtrol = listColControl[buttonNum - 1];
//原图
Bitmap primaryBitmap = ((DocumentWorkspace)sender).CompositionSurface.CreateAliasedBitmap();// CompositionSurface.CreateAliasedBitmap();
//克隆原图
Bitmap newBit = primaryBitmap.Clone(new Rectangle(0, 0, primaryBitmap.Width, primaryBitmap.Height), primaryBitmap.PixelFormat);
//新图(测量,标注,多相等信息带入)
Bitmap bitmap = ((DocumentWorkspace)sender).NewPanelBitmap(newBit);
Document document = Document.FromImage(bitmap);
if (((DocumentWorkspace)sender).phaseModels.Count > 0)
{
this.newColtrol.workspaceWindow.phaseModels.Add(((DocumentWorkspace)sender).AnalysisPhaseModel);//多相、二值
}
//this.newColtrol.workspaceWindow.GraphicsList = ((DocumentWorkspace)sender).GraphicsList;//测量、标注、多视场
string imgName = ((DocumentWorkspace)sender).GetFriendlyName();//图名名称
//暂时绘制出来获得尺寸
Graphics graphics = CreateGraphics();
string label_str = imgName;
string str = label_str;
SizeF sizeF = graphics.MeasureString(label_str, listColControl[buttonNum - 1].label.Font);
//判断图片名是否超过label长度
if (sizeF.Width >= listColControl[buttonNum - 1].label.Width - 10)
{
str = label_str.Substring(0, str.Length - 4);
sizeF = graphics.MeasureString(str, listColControl[buttonNum - 1].label.Font);
listColControl[buttonNum - 1].label.Text = str + "...";
}
else
{
listColControl[buttonNum - 1].label.Text = str;
}
listColControl[buttonNum - 1].workspaceWindow.Document = document;
listColControl[buttonNum - 1].workspaceWindow.GraphicsList = ((DocumentWorkspace)sender).GraphicsList;
listColControl[buttonNum - 1].workspaceWindow.ZoomBasis = ZoomBasis.ScaleFactor;
//重置缩放比
listColControl[buttonNum - 1].workspaceWindow.ScaleFactor = new ScaleFactor(10, 100);
listColControl[buttonNum - 1].workspaceWindow.ScaleFactor = new ScaleFactor(100, 100);
listColControl[buttonNum - 1].workspaceWindow.Visible = true;
if (listColControl[buttonNum - 1].isSelect)
{
ColControl_Click(listColControl[buttonNum - 1], EventArgs.Empty);
}
}
}
public Bitmap DeepClone(Bitmap bitmap)
{
Bitmap dstBitmap = null;
using (MemoryStream mStream = new MemoryStream())
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(mStream, bitmap);
mStream.Seek(0, SeekOrigin.Begin);//指定当前流的位置为流的开头。
dstBitmap = (Bitmap)bf.Deserialize(mStream);
mStream.Close();
}
return dstBitmap;
}
///
/// 点击自定义控件
///
///
///
private void ColControl_Click(object sender, EventArgs e)
{
isFirst = true;
if (sender is ColControl)
{
colNum = Convert.ToInt32(((ColControl)sender).Tag);//判断选中的是哪个控件
}
else if (sender is Panel)
{
colNum = Convert.ToInt32(((Panel)sender).Tag);//判断选中的是哪个控件
}
else if (sender is Ruler)
{
colNum = Convert.ToInt32(((Ruler)sender).Tag);//判断选中的是哪个控件
}
else if (sender is Button)
{
colNum = Convert.ToInt32(((Button)sender).Tag);//判断选中的是哪个控件
buttonNum = Convert.ToInt32(((Button)sender).Tag);
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();
}
}
}
for (int i = 0; i < listColControl.Count; i++)
{
this.listColControl[i].isSelect = false;
}
this.listColControl[colNum - 1].isSelect = true;
this.panel1.Refresh();
newColtrol = this.listColControl[colNum - 1];
if (this.listColControl[colNum - 1].workspaceWindow.CompositionSurface != null)
{
getRatioBetweenPanelWindowAndBitmap(this.listColControl[colNum - 1]);
if (newBitmap.Width > pictureBox1.Size.Width || newBitmap.Height > pictureBox1.Size.Height)
{
pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
}
else
{
pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
}
this.pictureBox1.Image = newBitmap;
this.pictureBox1.Paint += new PaintEventHandler(pictureBox1_Paint);
}
else
{
this.pictureBox1.Image = null;
this.textBox2.Text = null;
}
}
///
/// picturebox绘制矩形选中区域
///
///
///
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
if (this.pictureBox1.Image != null)
{
if (isFirst)
{
//获取缩略图对应矩形
PropertyInfo _ImageRectanglePropert = this.pictureBox1.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic);
imageRect = (Rectangle)_ImageRectanglePropert.GetValue(this.pictureBox1, null);
Point scPoint = newColtrol.workspaceWindow.PanelScrollPosition;//当前滚动条位置
double scRatioWidth = imageRect.Width / (newBitmap.Width * newColtrol.workspaceWindow.ScaleRatio);
double scRatioHeight = imageRect.Height / (newBitmap.Height * newColtrol.workspaceWindow.ScaleRatio);
//缩略图中红框选中区域
zoomRect = new Rectangle(imageRect.X + Convert.ToInt32(scPoint.X * scRatioWidth), imageRect.Y + Convert.ToInt32(scPoint.Y * scRatioHeight),
(int)(Math.Round(imageRect.Width * widthRatio)), (int)(Math.Round(imageRect.Height * heightRatio)));
//红框矩形的最小尺寸,即原图放大3200%
Size size = newColtrol.workspaceWindow.panel.ClientSize;
double minWidthRatio = size.Width / (newBitmap.Width * 32d);
double minHeightRatio = size.Height / (newBitmap.Height * 32d);
minRectWidth = (int)(Math.Round(imageRect.Width * minWidthRatio));
minRectHeight = (int)(Math.Round(imageRect.Height * minHeightRatio));
}
e.Graphics.DrawRectangle(new Pen(Color.Red), zoomRect.X, zoomRect.Y, zoomRect.Width - 1, zoomRect.Height - 1);
e.Graphics.FillRectangle(new SolidBrush(Color.Black), new Rectangle(zoomRect.Right - 3, zoomRect.Bottom - 3, 7, 7));
this.textBox2.Text = Math.Round(newColtrol.workspaceWindow.ScaleFactor.Ratio * 100) + "%";
this.textBox2.Refresh();
}
}
///
/// 移动滚动条改变picture矩形框位置
///
///
///
private void scrollMovePictureBox(object sender, System.Windows.Forms.ScrollEventArgs e)
{
PanelEx panelEx = (PanelEx)sender;
ColControl colControl = (ColControl)panelEx.Parent.Parent.Parent;
int tag = (int)colControl.Tag;
if (this.pictureBox1.Image != null && colControl.isSelect)
{
//用自带的接口精度有问题
//int oldPosition = e.OldValue;
//int newPosition = e.NewValue;
//int rectPosition = newPosition - oldPosition;
Point scPoint = listColControl[tag - 1].workspaceWindow.PanelScrollPosition;
var whichScroll = e.ScrollOrientation;
double widthRatio2 = (double)imageRect.Width / ((double)newBitmap.Width * listColControl[tag - 1].workspaceWindow.ScaleRatio);
double heightRatio2 = (double)imageRect.Height / ((double)newBitmap.Height * listColControl[tag - 1].workspaceWindow.ScaleRatio);
//水平滚动条
if (whichScroll is System.Windows.Forms.ScrollOrientation.HorizontalScroll)
{
zoomRect.X = imageRect.X + Convert.ToInt32(Math.Round((double)scPoint.X * widthRatio2));
}
//垂直滚动条
if (whichScroll is System.Windows.Forms.ScrollOrientation.VerticalScroll)
{
zoomRect.Y = imageRect.Y + Convert.ToInt32(Math.Round((double)scPoint.Y * heightRatio2));
}
//copyRect = new Rectangle(zoomRect.X, zoomRect.Y, copyRect.Width, copyRect.Height);//是否要刷新100%的矩形位置
this.pictureBox1.Refresh();
}
}
///
/// 从大图中截取一部分图片
///
/// 来源图片
/// 从偏移X坐标位置开始截取
/// 从偏移Y坐标位置开始截取
/// 保存图片的宽度
/// 保存图片的高度
///
public Bitmap CaptureImage(Bitmap fromImage, int offsetX, int offsetY, int width, int height)
{
//创建新图位图
Bitmap bitmap = new Bitmap(width, height);
//创建作图区域
Graphics graphic = Graphics.FromImage(bitmap);
//截取原图相应区域写入作图区
graphic.DrawImage(fromImage, 0, 0, new Rectangle(offsetX, offsetY, width, height), GraphicsUnit.Pixel);
//从作图区生成新图
Bitmap saveImage = Bitmap.FromHbitmap(bitmap.GetHbitmap());
return saveImage;
////释放资源
//saveImage.Dispose();
//graphic.Dispose();
//bitmap.Dispose();
}
}
}