12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802 |
- using OpenCvSharp;
- using PaintDotNet.Adjust.BaseImage;
- using PaintDotNet.Base.CommTool;
- using PaintDotNet.Base.SettingModel;
- using PaintDotNet.CustomControl;
- using PaintDotNet.DbOpreate.DbBll;
- using PaintDotNet.DbOpreate.DbModel;
- using PaintDotNet.ImageCollect;
- using System;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.IO;
- using System.Windows.Forms;
- namespace PaintDotNet.Measuring
- {
- /// <summary>
- /// 标尺编辑/删除界面
- /// </summary>
- internal class RuleAddForm : PdnBaseForm
- {
- /// <summary>
- /// 公共按钮
- /// </summary>
- private CommonControlButtons commonControlButtons;
- /// <summary>
- /// 在各种弹窗中使用
- /// </summary>
- private DocumentWorkspaceWindow documentWorkspace;
- /// <summary>
- /// 步骤
- /// </summary>
- private byte step = 1;
- /// <summary>
- /// 方向
- /// </summary>
- private byte direction = 0;
- /// <summary>
- /// 标尺图片
- /// </summary>
- private Bitmap bitmap;
- /// <summary>
- /// 起止点
- /// </summary>
- private System.Drawing.Point startPoint, endPoint;
- /// <summary>
- /// x、y轴数值
- /// </summary>
- private int x, y;
- /// <summary>
- /// 绘制标尺的线宽
- /// </summary>
- private int width;
- /// <summary>
- /// 字体
- /// </summary>
- private Font font;
- /// <summary>
- /// 笔刷
- /// </summary>
- private Brush brush = new SolidBrush(Color.Red);
- /// <summary>
- /// 标尺xml文件,编辑标尺时使用
- /// </summary>
- public RulerFileModel ruleFileModel;
- /// <summary>
- /// 标尺数据,编辑标尺时使用
- /// </summary>
- public mic_rulers ruleModel;
- /// <summary>
- /// 1新增 2编辑
- /// </summary>
- public int status;
- /// <summary>
- /// 调色板
- /// </summary>
- PaintDotNet.ColorsForm colorsForm1;
- // Create the outline for our custom end cap.
- GraphicsPath hPath = new GraphicsPath();
- // Construct the hook-shaped end cap.
- CustomLineCap HookCap;
- public AppWorkspace appWorkspace;
- #region 像素跟踪
- private Mat mat, ImageROI, bmat = new Mat();
- /// <summary>
- /// rgb像素点
- /// </summary>
- private Vec3b bgr;
- /// <summary>
- /// hls像素点
- /// </summary>
- private double h, s, v;
- /// <summary>
- /// 缩放倍数
- /// </summary>
- private int scale;
- /// <summary>
- /// 中间十字和圆的颜色
- /// 根据左侧的panel的被选中的背景色变化
- /// </summary>
- private Color color = Color.Red;
- /// <summary>
- /// 按下标记
- /// </summary>
- private bool pressFlag;
- #endregion
- #region 控件
- private System.Windows.Forms.GroupBox groupBox1;
- private System.Windows.Forms.Button button1;
- private System.Windows.Forms.Button button3;
- private System.Windows.Forms.Button button2;
- private System.Windows.Forms.GroupBox groupBox2;
- private System.Windows.Forms.Button button4;
- private System.Windows.Forms.Button button5;
- private System.Windows.Forms.Button button6;
- private System.Windows.Forms.Button button9;
- private System.Windows.Forms.Button button8;
- private System.Windows.Forms.Button button7;
- private System.Windows.Forms.Panel panel1;
- private System.Windows.Forms.Label label7;
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.NumericUpDown numericUpDown1;
- private System.Windows.Forms.ColorDialog colorDialog1;
- private System.Windows.Forms.GroupBox groupBox3;
- private System.Windows.Forms.GroupBox groupBox4;
- private System.Windows.Forms.TextBox textBox1;
- private System.Windows.Forms.TextBox textBox6;
- private System.Windows.Forms.TextBox textBox5;
- private System.Windows.Forms.TextBox textBox4;
- private System.Windows.Forms.TextBox textBox2;
- private System.Windows.Forms.GroupBox groupBox5;
- private System.Windows.Forms.TextBox textBox12;
- private System.Windows.Forms.TextBox textBox11;
- private System.Windows.Forms.TextBox textBox10;
- private System.Windows.Forms.TextBox textBox9;
- private System.Windows.Forms.TextBox textBox8;
- private System.Windows.Forms.TextBox textBox7;
- private System.Windows.Forms.Panel panel2;
- private CustomControl.LinearColorPickerControl linearColorPickerControl1;
- private PictureBox pictureBox1;
- private Label label6;
- private Label label5;
- private Label label4;
- private Label label3;
- private Label label2;
- private Label label8;
- private Label label9;
- private TrackBar trackBar1;
- private NumericUpDown numericUpDown2;
- private Label label10;
- private Label label11;
- private Label label17;
- private Label label16;
- private Label label15;
- private Label label14;
- private Label label13;
- private Label label12;
- private Label label23;
- private Label label22;
- private Label label21;
- private Label label20;
- private Label label19;
- private Label label18;
- private NumericUpDown numericUpDown3;
- private Label label24;
- private System.Windows.Forms.ComboBox comboBox1;
- #endregion
- #region Windows Form Designer generated code
- private void InitializeLanguageText()
- {
- this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
- this.button6.Text = PdnResources.GetString("Menu.Previous.text");
- this.button5.Text = PdnResources.GetString("Menu.Nextstep.text");
- this.button3.Text = PdnResources.GetString("Menu.thirdstep.text");
- this.button2.Text = PdnResources.GetString("Menu.Secondstep.text");
- this.button1.Text = PdnResources.GetString("Menu.firststep.text");
- this.groupBox2.Text = PdnResources.GetString("Menu.Selectimagefrom.text");
- this.label1.Text = PdnResources.GetString("Menu.Linewidth.text") + ":";
- this.label7.Text = PdnResources.GetString("Menu.color.text") + ":";
- this.button9.Text = PdnResources.GetString("Menu.Anydirection.text");
- this.button8.Text = PdnResources.GetString("Menu.Verticaldirection.text");
- this.button7.Text = PdnResources.GetString("Menu.horizontaldirection.text");
- this.button4.Text = PdnResources.GetString("Menu.Openimage.text");
- this.groupBox3.Text = PdnResources.GetString("Menu.Rulerimage.text");
- this.groupBox4.Text = PdnResources.GetString("Menu.params.text");
- this.label17.Text = PdnResources.GetString("Menu.Pixellength.text") + ":";
- this.label16.Text = PdnResources.GetString("Menu.Physicallength.text") + ":";
- this.label15.Text = PdnResources.GetString("Menu.Resolution.text") + ":";
- this.label14.Text = PdnResources.GetString("Menu.unit.text") + ":";
- this.label13.Text = PdnResources.GetString("Menu.LabelAction.DrawGainNumber.Text") + ":";
- this.label12.Text = PdnResources.GetString("Menu.name.text") + ":";
- this.groupBox5.Text = PdnResources.GetString("Menu.Expand.text");
- this.label23.Text = PdnResources.GetString("Menu.microscope.text") + ":";
- this.label22.Text = PdnResources.GetString("Menu.Objectlens.text") + ":";
- this.label21.Text = PdnResources.GetString("Menu.thecamera.text") + ":";
- this.label20.Text = PdnResources.GetString("Menu.oculars.text") + ":";
- this.label19.Text = PdnResources.GetString("Menu.interface.text") + ":";
- this.label18.Text = PdnResources.GetString("Menu.magnificationchanger.text") + ":";
- this.label9.Text = PdnResources.GetString("Menu.Times.text");
- this.label24.Text = PdnResources.GetString("Menu.Fontsize.text");
- }
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.button6 = new System.Windows.Forms.Button();
- this.button5 = new System.Windows.Forms.Button();
- this.button3 = new System.Windows.Forms.Button();
- this.button2 = new System.Windows.Forms.Button();
- this.button1 = new System.Windows.Forms.Button();
- this.groupBox2 = new System.Windows.Forms.GroupBox();
- this.label24 = new System.Windows.Forms.Label();
- this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
- this.numericUpDown3 = new System.Windows.Forms.NumericUpDown();
- this.label1 = new System.Windows.Forms.Label();
- this.panel1 = new System.Windows.Forms.Panel();
- this.label7 = new System.Windows.Forms.Label();
- this.button9 = new System.Windows.Forms.Button();
- this.button8 = new System.Windows.Forms.Button();
- this.button7 = new System.Windows.Forms.Button();
- this.button4 = new System.Windows.Forms.Button();
- this.colorDialog1 = new System.Windows.Forms.ColorDialog();
- this.groupBox3 = new System.Windows.Forms.GroupBox();
- this.groupBox4 = new System.Windows.Forms.GroupBox();
- this.label17 = new System.Windows.Forms.Label();
- this.label16 = new System.Windows.Forms.Label();
- this.label15 = new System.Windows.Forms.Label();
- this.label14 = new System.Windows.Forms.Label();
- this.label13 = new System.Windows.Forms.Label();
- this.label12 = new System.Windows.Forms.Label();
- this.comboBox1 = new System.Windows.Forms.ComboBox();
- this.textBox6 = new System.Windows.Forms.TextBox();
- this.textBox5 = new System.Windows.Forms.TextBox();
- this.textBox4 = new System.Windows.Forms.TextBox();
- this.textBox2 = new System.Windows.Forms.TextBox();
- this.textBox1 = new System.Windows.Forms.TextBox();
- this.groupBox5 = new System.Windows.Forms.GroupBox();
- this.label23 = new System.Windows.Forms.Label();
- this.label22 = new System.Windows.Forms.Label();
- this.label21 = new System.Windows.Forms.Label();
- this.label20 = new System.Windows.Forms.Label();
- this.label19 = new System.Windows.Forms.Label();
- this.label18 = new System.Windows.Forms.Label();
- this.textBox12 = new System.Windows.Forms.TextBox();
- this.textBox11 = new System.Windows.Forms.TextBox();
- this.textBox10 = new System.Windows.Forms.TextBox();
- this.textBox9 = new System.Windows.Forms.TextBox();
- this.textBox8 = new System.Windows.Forms.TextBox();
- this.textBox7 = new System.Windows.Forms.TextBox();
- this.panel2 = new System.Windows.Forms.Panel();
- this.label10 = new System.Windows.Forms.Label();
- this.label11 = new System.Windows.Forms.Label();
- this.label9 = new System.Windows.Forms.Label();
- this.trackBar1 = new System.Windows.Forms.TrackBar();
- this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
- this.label6 = new System.Windows.Forms.Label();
- this.label5 = new System.Windows.Forms.Label();
- this.label4 = new System.Windows.Forms.Label();
- this.label3 = new System.Windows.Forms.Label();
- this.label2 = new System.Windows.Forms.Label();
- this.label8 = new System.Windows.Forms.Label();
- this.pictureBox1 = new System.Windows.Forms.PictureBox();
- this.linearColorPickerControl1 = new PaintDotNet.CustomControl.LinearColorPickerControl();
- this.groupBox1.SuspendLayout();
- this.groupBox2.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).BeginInit();
- this.groupBox4.SuspendLayout();
- this.groupBox5.SuspendLayout();
- this.panel2.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
- ((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.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)));
- this.groupBox1.Controls.Add(this.button6);
- this.groupBox1.Controls.Add(this.button5);
- this.groupBox1.Controls.Add(this.button3);
- this.groupBox1.Controls.Add(this.button2);
- this.groupBox1.Controls.Add(this.button1);
- this.groupBox1.Location = new System.Drawing.Point(13, 13);
- this.groupBox1.Name = "groupBox1";
- this.groupBox1.Size = new System.Drawing.Size(115, 445);
- this.groupBox1.TabIndex = 1;
- this.groupBox1.TabStop = false;
- //
- // button6
- //
- this.button6.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.button6.Location = new System.Drawing.Point(20, 383);
- this.button6.Name = "button6";
- this.button6.Size = new System.Drawing.Size(75, 23);
- this.button6.TabIndex = 4;
- this.button6.Text = "上一步";
- this.button6.UseVisualStyleBackColor = true;
- this.button6.Click += new System.EventHandler(this.button6_Click);
- //
- // button5
- //
- this.button5.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.button5.Location = new System.Drawing.Point(20, 412);
- this.button5.Name = "button5";
- this.button5.Size = new System.Drawing.Size(75, 23);
- this.button5.TabIndex = 3;
- this.button5.Text = "下一步";
- this.button5.UseVisualStyleBackColor = true;
- this.button5.Click += new System.EventHandler(this.button5_Click);
- //
- // button3
- //
- this.button3.Location = new System.Drawing.Point(20, 89);
- this.button3.Name = "button3";
- this.button3.Size = new System.Drawing.Size(75, 23);
- this.button3.TabIndex = 2;
- this.button3.Text = "第三步";
- this.button3.UseVisualStyleBackColor = true;
- this.button3.Click += new System.EventHandler(this.button3_Click);
- //
- // button2
- //
- this.button2.Location = new System.Drawing.Point(20, 59);
- this.button2.Name = "button2";
- this.button2.Size = new System.Drawing.Size(75, 23);
- this.button2.TabIndex = 1;
- this.button2.Text = "第二步";
- this.button2.UseVisualStyleBackColor = true;
- this.button2.Click += new System.EventHandler(this.button2_Click);
- //
- // button1
- //
- this.button1.Location = new System.Drawing.Point(20, 29);
- this.button1.Name = "button1";
- this.button1.Size = new System.Drawing.Size(75, 23);
- this.button1.TabIndex = 0;
- this.button1.Text = "第一步";
- this.button1.UseVisualStyleBackColor = true;
- this.button1.Click += new System.EventHandler(this.button1_Click);
- //
- // groupBox2
- //
- this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox2.Controls.Add(this.label24);
- this.groupBox2.Controls.Add(this.numericUpDown1);
- this.groupBox2.Controls.Add(this.numericUpDown3);
- this.groupBox2.Controls.Add(this.label1);
- this.groupBox2.Controls.Add(this.panel1);
- this.groupBox2.Controls.Add(this.label7);
- this.groupBox2.Controls.Add(this.button9);
- this.groupBox2.Controls.Add(this.button8);
- this.groupBox2.Controls.Add(this.button7);
- this.groupBox2.Controls.Add(this.button4);
- this.groupBox2.Location = new System.Drawing.Point(134, 13);
- this.groupBox2.Name = "groupBox2";
- this.groupBox2.Size = new System.Drawing.Size(779, 52);
- this.groupBox2.TabIndex = 2;
- this.groupBox2.TabStop = false;
- this.groupBox2.Text = "从...选择图像";
- //
- // label24
- //
- this.label24.AutoSize = true;
- this.label24.Location = new System.Drawing.Point(278, 26);
- this.label24.Name = "label24";
- this.label24.Size = new System.Drawing.Size(41, 12);
- this.label24.TabIndex = 16;
- this.label24.Text = "字号:";
- //
- // numericUpDown1
- //
- this.numericUpDown1.Location = new System.Drawing.Point(181, 22);
- this.numericUpDown1.Maximum = new decimal(new int[] {
- 99999,
- 0,
- 0,
- 0});
- this.numericUpDown1.Minimum = new decimal(new int[] {
- 1,
- 0,
- 0,
- 0});
- this.numericUpDown1.Name = "numericUpDown1";
- this.numericUpDown1.Size = new System.Drawing.Size(72, 21);
- this.numericUpDown1.TabIndex = 15;
- this.numericUpDown1.Value = new decimal(new int[] {
- 3,
- 0,
- 0,
- 0});
- this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged);
- //
- // numericUpDown3
- //
- this.numericUpDown3.Location = new System.Drawing.Point(323, 22);
- this.numericUpDown3.Maximum = new decimal(new int[] {
- 49000,
- 0,
- 0,
- 0});
- this.numericUpDown3.Minimum = new decimal(new int[] {
- 1,
- 0,
- 0,
- 0});
- this.numericUpDown3.Name = "numericUpDown3";
- this.numericUpDown3.Size = new System.Drawing.Size(72, 21);
- this.numericUpDown3.TabIndex = 17;
- this.numericUpDown3.Value = new decimal(new int[] {
- 12,
- 0,
- 0,
- 0});
- this.numericUpDown3.ValueChanged += new System.EventHandler(this.numericUpDown3_ValueChanged);
- //
- // label1
- //
- this.label1.AutoSize = true;
- this.label1.Location = new System.Drawing.Point(136, 26);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(41, 12);
- this.label1.TabIndex = 4;
- this.label1.Text = "线宽:";
- //
- // panel1
- //
- this.panel1.BackColor = System.Drawing.Color.Red;
- this.panel1.Location = new System.Drawing.Point(55, 22);
- this.panel1.Name = "panel1";
- this.panel1.Size = new System.Drawing.Size(72, 21);
- this.panel1.TabIndex = 14;
- this.panel1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel1_MouseDown);
- //
- // label7
- //
- this.label7.AutoSize = true;
- this.label7.Location = new System.Drawing.Point(13, 26);
- this.label7.Name = "label7";
- this.label7.Size = new System.Drawing.Size(41, 12);
- this.label7.TabIndex = 13;
- this.label7.Text = "颜色:";
- //
- // button9
- //
- this.button9.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.button9.Location = new System.Drawing.Point(617, 21);
- this.button9.Name = "button9";
- this.button9.Size = new System.Drawing.Size(75, 23);
- this.button9.TabIndex = 3;
- this.button9.Text = "任意方向";
- this.button9.UseVisualStyleBackColor = true;
- this.button9.Click += new System.EventHandler(this.button9_Click);
- //
- // button8
- //
- this.button8.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.button8.Location = new System.Drawing.Point(535, 21);
- this.button8.Name = "button8";
- this.button8.Size = new System.Drawing.Size(75, 23);
- this.button8.TabIndex = 2;
- this.button8.Text = "垂直方向";
- this.button8.UseVisualStyleBackColor = true;
- this.button8.Click += new System.EventHandler(this.button8_Click);
- //
- // button7
- //
- this.button7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.button7.Location = new System.Drawing.Point(453, 21);
- this.button7.Name = "button7";
- this.button7.Size = new System.Drawing.Size(75, 23);
- this.button7.TabIndex = 1;
- this.button7.Text = "水平方向";
- this.button7.UseVisualStyleBackColor = true;
- this.button7.Click += new System.EventHandler(this.button7_Click);
- //
- // button4
- //
- this.button4.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.button4.Location = new System.Drawing.Point(698, 21);
- this.button4.Name = "button4";
- this.button4.Size = new System.Drawing.Size(75, 23);
- this.button4.TabIndex = 0;
- this.button4.Text = "保存标尺";
- this.button4.UseVisualStyleBackColor = true;
- this.button4.Click += new System.EventHandler(this.button4_Click);
- //
- // groupBox3
- //
- this.groupBox3.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.groupBox3.Location = new System.Drawing.Point(135, 72);
- this.groupBox3.Name = "groupBox3";
- this.groupBox3.Size = new System.Drawing.Size(585, 386);
- this.groupBox3.TabIndex = 3;
- this.groupBox3.TabStop = false;
- this.groupBox3.Text = "标尺图像";
- //
- // groupBox4
- //
- this.groupBox4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox4.Controls.Add(this.label17);
- this.groupBox4.Controls.Add(this.label16);
- this.groupBox4.Controls.Add(this.label15);
- this.groupBox4.Controls.Add(this.label14);
- this.groupBox4.Controls.Add(this.label13);
- this.groupBox4.Controls.Add(this.label12);
- this.groupBox4.Controls.Add(this.comboBox1);
- this.groupBox4.Controls.Add(this.textBox6);
- this.groupBox4.Controls.Add(this.textBox5);
- this.groupBox4.Controls.Add(this.textBox4);
- this.groupBox4.Controls.Add(this.textBox2);
- this.groupBox4.Controls.Add(this.textBox1);
- this.groupBox4.Location = new System.Drawing.Point(726, 72);
- this.groupBox4.Name = "groupBox4";
- this.groupBox4.Size = new System.Drawing.Size(187, 189);
- this.groupBox4.TabIndex = 4;
- this.groupBox4.TabStop = false;
- this.groupBox4.Visible = false;
- //
- // label17
- //
- this.label17.AutoSize = true;
- this.label17.Location = new System.Drawing.Point(9, 164);
- this.label17.Name = "label17";
- this.label17.Size = new System.Drawing.Size(0, 12);
- this.label17.TabIndex = 13;
- //
- // label16
- //
- this.label16.AutoSize = true;
- this.label16.Location = new System.Drawing.Point(9, 136);
- this.label16.Name = "label16";
- this.label16.Size = new System.Drawing.Size(0, 12);
- this.label16.TabIndex = 12;
- //
- // label15
- //
- this.label15.AutoSize = true;
- this.label15.Location = new System.Drawing.Point(9, 108);
- this.label15.Name = "label15";
- this.label15.Size = new System.Drawing.Size(0, 12);
- this.label15.TabIndex = 11;
- //
- // label14
- //
- this.label14.AutoSize = true;
- this.label14.Location = new System.Drawing.Point(9, 80);
- this.label14.Name = "label14";
- this.label14.Size = new System.Drawing.Size(0, 12);
- this.label14.TabIndex = 10;
- //
- // label13
- //
- this.label13.AutoSize = true;
- this.label13.Location = new System.Drawing.Point(9, 52);
- this.label13.Name = "label13";
- this.label13.Size = new System.Drawing.Size(0, 12);
- this.label13.TabIndex = 9;
- //
- // label12
- //
- this.label12.AutoSize = true;
- this.label12.Location = new System.Drawing.Point(9, 24);
- this.label12.Name = "label12";
- this.label12.Size = new System.Drawing.Size(0, 12);
- this.label12.TabIndex = 8;
- //
- // comboBox1
- //
- this.comboBox1.FormattingEnabled = true;
- this.comboBox1.Location = new System.Drawing.Point(75, 76);
- this.comboBox1.Name = "comboBox1";
- this.comboBox1.Size = new System.Drawing.Size(106, 20);
- this.comboBox1.TabIndex = 7;
- //
- // textBox6
- //
- this.textBox6.Location = new System.Drawing.Point(75, 160);
- this.textBox6.Name = "textBox6";
- this.textBox6.Size = new System.Drawing.Size(106, 21);
- this.textBox6.TabIndex = 6;
- //
- // textBox5
- //
- this.textBox5.Location = new System.Drawing.Point(75, 132);
- this.textBox5.Name = "textBox5";
- this.textBox5.Size = new System.Drawing.Size(106, 21);
- this.textBox5.TabIndex = 5;
- //
- // textBox4
- //
- this.textBox4.Location = new System.Drawing.Point(75, 104);
- this.textBox4.Name = "textBox4";
- this.textBox4.Size = new System.Drawing.Size(106, 21);
- this.textBox4.TabIndex = 4;
- //
- // textBox2
- //
- this.textBox2.Location = new System.Drawing.Point(76, 48);
- this.textBox2.Name = "textBox2";
- this.textBox2.Size = new System.Drawing.Size(106, 21);
- this.textBox2.TabIndex = 2;
- //
- // textBox1
- //
- this.textBox1.Location = new System.Drawing.Point(75, 20);
- this.textBox1.Name = "textBox1";
- this.textBox1.Size = new System.Drawing.Size(106, 21);
- this.textBox1.TabIndex = 1;
- //
- // groupBox5
- //
- this.groupBox5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
- this.groupBox5.Controls.Add(this.label23);
- this.groupBox5.Controls.Add(this.label22);
- this.groupBox5.Controls.Add(this.label21);
- this.groupBox5.Controls.Add(this.label20);
- this.groupBox5.Controls.Add(this.label19);
- this.groupBox5.Controls.Add(this.label18);
- this.groupBox5.Controls.Add(this.textBox12);
- this.groupBox5.Controls.Add(this.textBox11);
- this.groupBox5.Controls.Add(this.textBox10);
- this.groupBox5.Controls.Add(this.textBox9);
- this.groupBox5.Controls.Add(this.textBox8);
- this.groupBox5.Controls.Add(this.textBox7);
- this.groupBox5.Location = new System.Drawing.Point(726, 267);
- this.groupBox5.Name = "groupBox5";
- this.groupBox5.Size = new System.Drawing.Size(187, 191);
- this.groupBox5.TabIndex = 5;
- this.groupBox5.TabStop = false;
- this.groupBox5.Visible = false;
- //
- // label23
- //
- this.label23.AutoSize = true;
- this.label23.Location = new System.Drawing.Point(9, 165);
- this.label23.Name = "label23";
- this.label23.Size = new System.Drawing.Size(0, 12);
- this.label23.TabIndex = 11;
- //
- // label22
- //
- this.label22.AutoSize = true;
- this.label22.Location = new System.Drawing.Point(9, 137);
- this.label22.Name = "label22";
- this.label22.Size = new System.Drawing.Size(0, 12);
- this.label22.TabIndex = 10;
- //
- // label21
- //
- this.label21.AutoSize = true;
- this.label21.Location = new System.Drawing.Point(9, 109);
- this.label21.Name = "label21";
- this.label21.Size = new System.Drawing.Size(0, 12);
- this.label21.TabIndex = 9;
- //
- // label20
- //
- this.label20.AutoSize = true;
- this.label20.Location = new System.Drawing.Point(9, 81);
- this.label20.Name = "label20";
- this.label20.Size = new System.Drawing.Size(0, 12);
- this.label20.TabIndex = 8;
- //
- // label19
- //
- this.label19.AutoSize = true;
- this.label19.Location = new System.Drawing.Point(9, 53);
- this.label19.Name = "label19";
- this.label19.Size = new System.Drawing.Size(0, 12);
- this.label19.TabIndex = 7;
- //
- // label18
- //
- this.label18.AutoSize = true;
- this.label18.Location = new System.Drawing.Point(9, 25);
- this.label18.Name = "label18";
- this.label18.Size = new System.Drawing.Size(0, 12);
- this.label18.TabIndex = 6;
- //
- // textBox12
- //
- this.textBox12.Location = new System.Drawing.Point(75, 161);
- this.textBox12.Name = "textBox12";
- this.textBox12.Size = new System.Drawing.Size(106, 21);
- this.textBox12.TabIndex = 5;
- //
- // textBox11
- //
- this.textBox11.Location = new System.Drawing.Point(75, 133);
- this.textBox11.Name = "textBox11";
- this.textBox11.Size = new System.Drawing.Size(106, 21);
- this.textBox11.TabIndex = 4;
- //
- // textBox10
- //
- this.textBox10.Location = new System.Drawing.Point(75, 105);
- this.textBox10.Name = "textBox10";
- this.textBox10.Size = new System.Drawing.Size(106, 21);
- this.textBox10.TabIndex = 3;
- //
- // textBox9
- //
- this.textBox9.Location = new System.Drawing.Point(75, 77);
- this.textBox9.Name = "textBox9";
- this.textBox9.Size = new System.Drawing.Size(106, 21);
- this.textBox9.TabIndex = 2;
- //
- // textBox8
- //
- this.textBox8.Location = new System.Drawing.Point(75, 49);
- this.textBox8.Name = "textBox8";
- this.textBox8.Size = new System.Drawing.Size(106, 21);
- this.textBox8.TabIndex = 1;
- //
- // textBox7
- //
- this.textBox7.Location = new System.Drawing.Point(75, 21);
- this.textBox7.Name = "textBox7";
- this.textBox7.Size = new System.Drawing.Size(106, 21);
- this.textBox7.TabIndex = 0;
- //
- // panel2
- //
- this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.panel2.BackColor = System.Drawing.SystemColors.Control;
- this.panel2.Controls.Add(this.label10);
- this.panel2.Controls.Add(this.label11);
- this.panel2.Controls.Add(this.label9);
- this.panel2.Controls.Add(this.trackBar1);
- this.panel2.Controls.Add(this.numericUpDown2);
- this.panel2.Controls.Add(this.label6);
- this.panel2.Controls.Add(this.label5);
- this.panel2.Controls.Add(this.label4);
- this.panel2.Controls.Add(this.label3);
- this.panel2.Controls.Add(this.label2);
- this.panel2.Controls.Add(this.label8);
- this.panel2.Controls.Add(this.pictureBox1);
- this.panel2.Controls.Add(this.linearColorPickerControl1);
- this.panel2.Location = new System.Drawing.Point(726, 79);
- this.panel2.Name = "panel2";
- this.panel2.Size = new System.Drawing.Size(187, 379);
- this.panel2.TabIndex = 0;
- this.panel2.Visible = false;
- //
- // label10
- //
- this.label10.AutoSize = true;
- this.label10.BackColor = System.Drawing.Color.Transparent;
- this.label10.Location = new System.Drawing.Point(6, 22);
- this.label10.Name = "label10";
- this.label10.Size = new System.Drawing.Size(17, 12);
- this.label10.TabIndex = 30;
- this.label10.Text = "Y=";
- //
- // label11
- //
- this.label11.AutoSize = true;
- this.label11.BackColor = System.Drawing.Color.Transparent;
- this.label11.Location = new System.Drawing.Point(6, 6);
- this.label11.Name = "label11";
- this.label11.Size = new System.Drawing.Size(17, 12);
- this.label11.TabIndex = 29;
- this.label11.Text = "X=";
- //
- // label9
- //
- this.label9.AutoSize = true;
- this.label9.Location = new System.Drawing.Point(47, 113);
- this.label9.Name = "label9";
- this.label9.Size = new System.Drawing.Size(0, 12);
- this.label9.TabIndex = 28;
- //
- // trackBar1
- //
- this.trackBar1.Location = new System.Drawing.Point(70, 109);
- this.trackBar1.Minimum = 1;
- this.trackBar1.Name = "trackBar1";
- this.trackBar1.Size = new System.Drawing.Size(91, 45);
- this.trackBar1.TabIndex = 27;
- this.trackBar1.TickStyle = System.Windows.Forms.TickStyle.None;
- this.trackBar1.Value = 1;
- this.trackBar1.ValueChanged += new System.EventHandler(this.trackBar1_ValueChanged);
- //
- // numericUpDown2
- //
- this.numericUpDown2.Location = new System.Drawing.Point(6, 109);
- this.numericUpDown2.Maximum = new decimal(new int[] {
- 10,
- 0,
- 0,
- 0});
- this.numericUpDown2.Minimum = new decimal(new int[] {
- 1,
- 0,
- 0,
- 0});
- this.numericUpDown2.Name = "numericUpDown2";
- this.numericUpDown2.Size = new System.Drawing.Size(37, 21);
- this.numericUpDown2.TabIndex = 26;
- this.numericUpDown2.Value = new decimal(new int[] {
- 1,
- 0,
- 0,
- 0});
- this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown2_ValueChanged);
- //
- // label6
- //
- this.label6.AutoSize = true;
- this.label6.Location = new System.Drawing.Point(126, 90);
- this.label6.Name = "label6";
- this.label6.Size = new System.Drawing.Size(11, 12);
- this.label6.TabIndex = 25;
- this.label6.Text = "V";
- //
- // label5
- //
- this.label5.AutoSize = true;
- this.label5.Location = new System.Drawing.Point(126, 74);
- this.label5.Name = "label5";
- this.label5.Size = new System.Drawing.Size(11, 12);
- this.label5.TabIndex = 24;
- this.label5.Text = "S";
- //
- // label4
- //
- this.label4.AutoSize = true;
- this.label4.Location = new System.Drawing.Point(126, 58);
- this.label4.Name = "label4";
- this.label4.Size = new System.Drawing.Size(11, 12);
- this.label4.TabIndex = 23;
- this.label4.Text = "H";
- //
- // label3
- //
- this.label3.AutoSize = true;
- this.label3.Location = new System.Drawing.Point(126, 36);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(11, 12);
- this.label3.TabIndex = 22;
- this.label3.Text = "B";
- //
- // label2
- //
- this.label2.AutoSize = true;
- this.label2.Location = new System.Drawing.Point(126, 20);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(11, 12);
- this.label2.TabIndex = 21;
- this.label2.Text = "G";
- //
- // label8
- //
- this.label8.AutoSize = true;
- this.label8.Location = new System.Drawing.Point(126, 4);
- this.label8.Name = "label8";
- this.label8.Size = new System.Drawing.Size(35, 12);
- this.label8.TabIndex = 20;
- this.label8.Text = "R=255";
- //
- // pictureBox1
- //
- this.pictureBox1.Location = new System.Drawing.Point(3, 3);
- this.pictureBox1.Name = "pictureBox1";
- this.pictureBox1.Size = new System.Drawing.Size(100, 100);
- this.pictureBox1.TabIndex = 19;
- this.pictureBox1.TabStop = false;
- this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
- //
- // linearColorPickerControl1
- //
- this.linearColorPickerControl1.Count = 1;
- this.linearColorPickerControl1.CustomGradient = new System.Drawing.Color[] {
- System.Drawing.Color.White,
- System.Drawing.Color.Yellow,
- System.Drawing.Color.Red,
- System.Drawing.Color.Green,
- System.Drawing.Color.Blue,
- System.Drawing.Color.Black};
- this.linearColorPickerControl1.DrawFarNub = true;
- this.linearColorPickerControl1.DrawNearNub = true;
- this.linearColorPickerControl1.Location = new System.Drawing.Point(106, 3);
- this.linearColorPickerControl1.MaxColor = System.Drawing.Color.White;
- this.linearColorPickerControl1.MinColor = System.Drawing.Color.Black;
- this.linearColorPickerControl1.Name = "linearColorPickerControl1";
- this.linearColorPickerControl1.Orientation = System.Windows.Forms.Orientation.Vertical;
- this.linearColorPickerControl1.Size = new System.Drawing.Size(14, 100);
- this.linearColorPickerControl1.TabIndex = 18;
- this.linearColorPickerControl1.TabStop = false;
- this.linearColorPickerControl1.Value = 153;
- this.linearColorPickerControl1.ValueChanged += new PaintDotNet.IndexEventHandler(this.linearColorPickerControl1_ValueChanged);
- //
- // RuleAddForm
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(922, 467);
- this.Controls.Add(this.panel2);
- this.Controls.Add(this.groupBox5);
- this.Controls.Add(this.groupBox4);
- this.Controls.Add(this.groupBox3);
- this.Controls.Add(this.groupBox2);
- this.Controls.Add(this.groupBox1);
- this.Name = "RuleAddForm";
- this.Text = "新建标尺";
- this.Controls.SetChildIndex(this.groupBox1, 0);
- this.Controls.SetChildIndex(this.groupBox2, 0);
- this.Controls.SetChildIndex(this.groupBox3, 0);
- this.Controls.SetChildIndex(this.groupBox4, 0);
- this.Controls.SetChildIndex(this.groupBox5, 0);
- this.Controls.SetChildIndex(this.panel2, 0);
- this.groupBox1.ResumeLayout(false);
- this.groupBox2.ResumeLayout(false);
- this.groupBox2.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).EndInit();
- this.groupBox4.ResumeLayout(false);
- this.groupBox4.PerformLayout();
- this.groupBox5.ResumeLayout(false);
- this.groupBox5.PerformLayout();
- this.panel2.ResumeLayout(false);
- this.panel2.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
- this.ResumeLayout(false);
- }
- #endregion
- //<summary>
- //初始化其他控件
- //</summary>
- private void InitOtherTools()
- {
- //
- //调色板
- //
- this.colorsForm1 = new ColorsForm();
- this.colorsForm1.StartPosition = FormStartPosition.CenterScreen;
- this.colorsForm1.setSaveBtn_Click(new System.EventHandler(this.colorsForm1Changed));
- //
- //字号
- //
- font = new Font("常规", (int)this.numericUpDown3.Value);
- }
- private void colorsForm1Changed(object sender, EventArgs e)
- {
- this.panel1.BackColor = this.colorsForm1.UserPrimaryColor.ToColor();
- this.colorsForm1.Close();
- }
- /// <summary>
- /// 像素跟踪的颜色控件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="ce"></param>
- private void linearColorPickerControl1_ValueChanged(object sender, IndexEventArgs ce)
- {
- this.color = this.linearColorPickerControl1.ValueToColor(this.linearColorPickerControl1.Value);
- this.pictureBox1.Refresh();
- }
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="status">1新增 2编辑</param>
- public RuleAddForm(int status, AppWorkspace appWorkspace)
- {
- this.status = status;
- this.appWorkspace = appWorkspace;
- InitializeComponent();
- InitializeLanguageText();
- InitOtherTools();
- this.Text = PdnResources.GetString("Menu.Imagement.Rulersetting.Newruler.text");
- //
- //初始化图像控件
- //
- this.documentWorkspace = new DocumentWorkspaceWindow(appWorkspace);
- this.documentWorkspace.Dock = DockStyle.Fill;
- this.documentWorkspace.HookMouseEvents();
- this.documentWorkspace.pixelTrackingEnabled = false;
- //this.documentWorkspace.SurfaceBox.RemoveMouseEvent();
- this.documentWorkspace.AuxiliaryLineEnabled = true;
- this.documentWorkspace.Visible = false;
- this.groupBox3.Controls.Add(documentWorkspace);
- //
- //初始化操作按钮
- //
- this.commonControlButtons = new CommonControlButtons();
- this.commonControlButtons.Dock = DockStyle.Top;
- this.commonControlButtons.Height = 30;
- this.groupBox3.Controls.Add(commonControlButtons);
- this.groupBox3.Width = this.groupBox3.Width + this.groupBox4.Width + 6;
- InitializeUI();
- this.comboBox1.Text = PdnResources.GetString("Menu.easeselectmeasurementunit.Text");
- this.comboBox1.DataSource = new BindingSource(InvariantData.ruleUnitsDictionary, null);
- this.comboBox1.DisplayMember = "Value";
- this.comboBox1.ValueMember = "Key";
- this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
- this.comboBox1.SelectedIndex = 4;
- InitializeHint();
- this.width = (int)this.numericUpDown1.Value;
- this.textBox4.ReadOnly = true;
- InitCommonButtonEvent();
- //自定义线形的线帽,已达到标尺垂线的效果
- hPath.AddLine(new PointF(-6, 0), new PointF(6, 0));
- HookCap = new CustomLineCap(null, hPath);
- HookCap.SetStrokeCaps(LineCap.Flat, LineCap.Flat);
- HookCap.WidthScale = 0.5f;
- }
- private void InitCommonButtonEvent()
- {
- this.commonControlButtons.zoomInButton.Click += new EventHandler(zoomInButton_Click);
- this.commonControlButtons.zoomOutButton.Click += new EventHandler(zoomOutButton_Click);
- this.commonControlButtons.zoomToWindowButton.Click += new EventHandler(zoomToWindowButton_Click);
- this.commonControlButtons.actualSizeButton.Click += new EventHandler(actualSizeButton_Click);
- this.commonControlButtons.pointerButton.Click += new EventHandler(pointerButton_Click);
- this.commonControlButtons.mobileModeButton.Click += new EventHandler(mobileModeButton_Click);
- }
- private void zoomInButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ZoomIn();
- }
- private void zoomOutButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ZoomOut();
- }
- private void zoomToWindowButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ZoomBasis = ZoomBasis.FitToWindow;
- }
- private void actualSizeButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ZoomBasis = ZoomBasis.ScaleFactor;
- this.documentWorkspace.ScaleFactor = ScaleFactor.OneToOne;
- }
- private void pointerButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.Pointer;
- }
- private void mobileModeButton_Click(object sender, EventArgs e)
- {
- this.documentWorkspace.ActiveTool = Annotation.Enum.DrawToolType.MoveMode;
- }
- /// <summary>
- /// 编辑时初始化数据
- /// </summary>
- public void InitializeEditData()
- {
- //打开图片
- if(ruleFileModel!=null && ruleFileModel.picBase64!=null)
- {
- //string base64Img = "data:image/png;base64," + ruleFileModel.picBase64;
- bitmap = DrawRulerHelper.Base64StringToImage(ruleFileModel.picBase64);
- Document document = Document.FromImage(bitmap);
- documentWorkspace.Document = document;
- this.documentWorkspace.Visible = true;
- startPoint = new System.Drawing.Point(ruleFileModel.startPointX, ruleFileModel.startPointY);
- endPoint = new System.Drawing.Point(ruleFileModel.endPointX, ruleFileModel.endPointY);
- this.panel1.BackColor = Color.FromArgb(ruleFileModel.lineColor);
- this.brush = new SolidBrush(this.panel1.BackColor);
- this.numericUpDown1.Value = ruleFileModel.lineWidth;
- this.numericUpDown3.Value = Math.Max(1, ruleFileModel.textSize);
- AddPictureBoxEvent();
- }
- if(ruleModel != null)
- {
- this.textBox2.Text = ruleModel.gain_multiple.ToString();
- this.textBox12.Text = ruleModel.microscope;
- this.textBox11.Text = ruleModel.objective_lens;
- this.textBox5.Text = ruleModel.physical_length.ToString();
- this.textBox6.Text = ruleModel.pixel_length.ToString();
- this.textBox10.Text = ruleModel.ruler_camera;
- this.textBox8.Text = ruleModel.ruler_connector;
- this.textBox9.Text = ruleModel.ruler_eyepiece;
- this.textBox1.Text = ruleModel.ruler_name;
- this.comboBox1.SelectedValue = ruleModel.ruler_units;
- this.textBox7.Text = ruleModel.ruler_zoom;
- this.textBox4.Text = ruleModel.ruler_width + "×" + ruleModel.ruler_height;
- }
- }
- private void MouseDownHandler(object sender, MouseEventArgs e)
- {
- if (documentWorkspace != null)
- {
- //if (documentWorkspace.Tool != null)
- // documentWorkspace.Tool.PerformMouseDown(e);
- }
- }
- private void MouseMoveHandler(object sender, MouseEventArgs e)
- {
- if (documentWorkspace != null)
- {
- //if (documentWorkspace.Tool != null)
- // documentWorkspace.Tool.PerformMouseMove(e);
- }
- }
- private void MouseUpHandler(object sender, MouseEventArgs e)
- {
- if (documentWorkspace != null)
- {
- //if (documentWorkspace.Tool != null)
- // documentWorkspace.Tool.PerformMouseUp(e);
- }
- }
- /// <summary>
- /// 打开图片/保存标尺
- /// 公用按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button4_Click(object sender, EventArgs e)
- {
- //保存标尺
- if (step == 3)
- {
- if (this.textBox1.Text.Equals(""))
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterarulername.text"));
- return;
- }
- if (this.textBox2.Text.Equals(""))
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterthemagnification.text"));
- return;
- }
- if (this.textBox5.Text.Equals(""))
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseenterthephysicallength.text"));
- return;
- }
- if (startPoint == endPoint)
- {
- MessageBox.Show(PdnResources.GetString("Menu.asereturntothesecondsteptodrawther.Text")+"!");
- return;
- }
- if (this.status == 1)
- {
- try
- {
- //判断标尺是否存在
- for (int i = 0; i < Startup.instance.mic_rulersAll.Count; i++)
- {
- if (Startup.instance.mic_rulersAll[i].ruler_name.Equals(this.textBox1.Text))
- {
- MessageBox.Show(PdnResources.GetString("Menu.hecurrentscalenamealreadyexists.Text"));
- return;
- }
- }
- //组织数据,保存到数据库
- mic_rulers rule = new mic_rulers();
- rule.gain_multiple = decimal.Parse(this.textBox2.Text);
- if (rule.gain_multiple<1)
- {
- MessageBox.Show("放大倍数错误,请检查!");
- return;
- }
- rule.microscope = this.textBox12.Text;
- rule.objective_lens = this.textBox11.Text;
- rule.physical_length = decimal.Parse(this.textBox5.Text);
- rule.pixel_length = float.Parse(this.textBox6.Text);
- rule.ruler_camera = this.textBox10.Text;
- rule.ruler_connector = this.textBox8.Text;
- rule.ruler_eyepiece = this.textBox9.Text;
- rule.ruler_height = this.bitmap.Height;
- rule.ruler_name = this.textBox1.Text;
- rule.ruler_units = (int)this.comboBox1.SelectedValue;
- rule.ruler_width = this.bitmap.Width;
- rule.ruler_zoom = this.textBox7.Text;
- rule.ruler_type = 1;
- mic_rulers_BLL.Add(rule);
- Startup.instance.mic_rulersAll.Add(rule);
- //生成xml文件
- ruleFileModel = new RulerFileModel();
- ruleFileModel.startPointX = startPoint.X;
- ruleFileModel.startPointY = startPoint.Y;
- ruleFileModel.endPointX = endPoint.X;
- ruleFileModel.endPointY = endPoint.Y;
- ruleFileModel.lineColor = this.panel1.BackColor.ToArgb();
- ruleFileModel.lineWidth = width;
- ruleFileModel.textSize = this.numericUpDown3.Value;
- ruleFileModel.picBase64 = DrawRulerHelper.ImgToBase64String(this.documentWorkspace.CompositionSurface.CreateAliasedBitmap());
- //保存xml文件
- string userInfoXml = XmlSerializeHelper.XmlSerialize<RulerFileModel>(ruleFileModel);
- string folderPath = Application.StartupPath + "\\RuleFile\\";
- if (!Directory.Exists(folderPath)) Directory.CreateDirectory(folderPath);
- string filePath = rule.id + ".xml";
- FileOperationHelper.WriteStringToFile(userInfoXml, folderPath + filePath, FileMode.Create);
- this.Close();
- }
- catch (Exception)
- {
- System.Console.WriteLine(e.ToString());
- MessageBox.Show(PdnResources.GetString("Menu.Rulerinformationsavingfaile.Text"));
- }
- }
- else if(this.status == 2)
- {
- try
- {
- //判断标尺是否存在
- for (int i = 0; i < Startup.instance.mic_rulersAll.Count; i++)
- {
- if (Startup.instance.mic_rulersAll[i].id == ruleModel.id)
- continue;
- if (Startup.instance.mic_rulersAll[i].ruler_name.Equals(this.textBox1.Text))
- {
- MessageBox.Show(PdnResources.GetString("Menu.hecurrentscalenamealreadyexists.Text"));
- return;
- }
- }
- //组织数据,保存到数据库
- ruleModel.gain_multiple = decimal.Parse(this.textBox2.Text);
- if (ruleModel.gain_multiple < 1)
- {
- MessageBox.Show("放大倍数错误,请检查!");
- return;
- }
- ruleModel.microscope = this.textBox12.Text;
- ruleModel.objective_lens = this.textBox11.Text;
- ruleModel.physical_length = decimal.Parse(this.textBox5.Text);
- ruleModel.pixel_length = float.Parse(this.textBox6.Text);
- ruleModel.ruler_camera = this.textBox10.Text;
- ruleModel.ruler_connector = this.textBox8.Text;
- ruleModel.ruler_eyepiece = this.textBox9.Text;
- ruleModel.ruler_height = this.bitmap.Height;
- ruleModel.ruler_name = this.textBox1.Text;
- ruleModel.ruler_units = (int)this.comboBox1.SelectedValue;
- ruleModel.ruler_width = this.bitmap.Width;
- ruleModel.ruler_zoom = this.textBox7.Text;
- ruleModel.ruler_type = 1;
- mic_rulers_BLL.Update(ruleModel);
- //生成xml文件
- ruleFileModel = new RulerFileModel();
- ruleFileModel.startPointX = startPoint.X;
- ruleFileModel.startPointY = startPoint.Y;
- ruleFileModel.endPointX = endPoint.X;
- ruleFileModel.endPointY = endPoint.Y;
- ruleFileModel.lineColor = this.panel1.BackColor.ToArgb();
- ruleFileModel.lineWidth = width;
- ruleFileModel.textSize = this.numericUpDown3.Value;
- ruleFileModel.picBase64 = DrawRulerHelper.ImgToBase64String(this.documentWorkspace.CompositionSurface.CreateAliasedBitmap());
- //保存xml文件
- string userInfoXml = XmlSerializeHelper.XmlSerialize<RulerFileModel>(ruleFileModel);
- string filePath = Application.StartupPath + "\\RuleFile\\" + ruleModel.id + ".xml";
- FileOperationHelper.WriteStringToFile(userInfoXml, filePath, FileMode.Create);
- this.Close();
- this.appWorkspace.RefreshActiveRuler();
- }
- catch (Exception)
- {
- System.Console.WriteLine(e.ToString());
- MessageBox.Show(PdnResources.GetString("Menu.Rulerinformationsavingfaile.Text"));
- }
- }
- //刷新标尺列表
- this.appWorkspace.RefueshRuleList();
- //刷新预览窗口
- if (CameraPreviewDialog.cameraPreviewDialog != null)
- CameraPreviewDialog.cameraPreviewDialog.BindingRule();
- }
- else
- {
- OpenFileDialog dialog = new OpenFileDialog();
- dialog.Filter = "图像文件(*.gif;*.jpg;*.jpeg;*.png)|*.gif;*.jpg;*.jpeg;*.png";
- dialog.ShowDialog();
- if (dialog.FileName != String.Empty)
- {
- try
- {
- bitmap = new Bitmap(dialog.FileName);
- Document document = Document.FromImage(bitmap);
- documentWorkspace.Document = document;
- this.documentWorkspace.Visible = true;
- this.textBox4.Text = bitmap.Width + "×" + bitmap.Height;
- this.mat = null;
- this.startPoint = System.Drawing.Point.Empty;
- this.endPoint = System.Drawing.Point.Empty;
- RemoveDocEvent();
- AddPictureBoxEvent();
- }
- catch(Exception)
- {
- MessageBox.Show("打开图像失败, 请确认");
- }
- }
- }
- }
- /// <summary>
- /// 下一步
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button5_Click(object sender, EventArgs e)
- {
- if (step == 1) {
- if (bitmap == null)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectrulerimage.Text")+"!");
- return;
- }
- }
- if (!this.panel2.Visible && !this.groupBox4.Visible)
- {
- this.groupBox3.Width = this.groupBox3.Width - this.groupBox4.Width - 3;
- }
- step++;
- InitializeUI();
- }
- /// <summary>
- /// 上一步
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button6_Click(object sender, EventArgs e)
- {
- step--;
- if (step == 1)
- {
- if (this.panel2.Visible || this.groupBox4.Visible)
- {
- this.groupBox3.Width = this.groupBox3.Width + this.groupBox4.Width + 3;
- }
- this.panel2.Visible = false;
- this.groupBox4.Visible = false;
- this.groupBox5.Visible = false;
- }
- InitializeUI();
- }
- /// <summary>
- /// 初始化UI
- /// </summary>
- private void InitializeUI() {
- if (step == 1) {
- this.label1.Visible = false;
- this.panel1.Visible = false;
- this.label7.Visible = false;
- this.label24.Visible = false;
- this.numericUpDown1.Visible = false;
- this.numericUpDown3.Visible = false;
- this.button7.Visible = false;
- this.button8.Visible = false;
- this.button9.Visible = false;
- this.button5.Enabled = true;
- this.button6.Enabled = false;
- this.button4.Visible = true;
- this.button4.Text = PdnResources.GetString("Menu.Openimage.text");
- this.button1.BackColor = Color.Black;
- this.button1.ForeColor = Color.White;
- this.button2.BackColor = Color.White;
- this.button2.ForeColor = Color.Black;
- this.button3.BackColor = Color.White;
- this.button3.ForeColor = Color.Black;
- }
- if (step == 2) {
- this.label1.Visible = true;
- this.panel1.Visible = true;
- this.label7.Visible = true;
- this.label24.Visible = true;
- this.numericUpDown1.Visible = true;
- this.numericUpDown3.Visible = true;
- this.button7.Visible = true;
- this.button8.Visible = true;
- this.button9.Visible = true;
- this.button6.Enabled = true;
- this.button5.Enabled = true;
- this.panel2.Visible = true;
- this.groupBox4.Visible = false;
- this.groupBox5.Visible = false;
- this.button4.Visible = false;
- this.button4.Text = PdnResources.GetString("Menu.Openimage.text");
- this.button2.BackColor = Color.Black;
- this.button2.ForeColor = Color.White;
- this.button1.BackColor = Color.White;
- this.button1.ForeColor = Color.Black;
- this.button3.BackColor = Color.White;
- this.button3.ForeColor = Color.Black;
- }
- if (step == 3) {
- this.label1.Visible = false;
- this.panel1.Visible = false;
- this.label7.Visible = false;
- this.label24.Visible = false;
- this.numericUpDown1.Visible = false;
- this.numericUpDown3.Visible = false;
- this.button7.Visible = false;
- this.button8.Visible = false;
- this.button9.Visible = false;
- this.button6.Enabled = true;
- this.button5.Enabled = false;
- this.button4.Visible = true;
- this.button4.Text = PdnResources.GetString("Menu.Savetheruler.text");
- this.panel2.Visible = false;
- this.groupBox4.Visible = true;
- this.groupBox5.Visible = true;
- this.button3.BackColor = Color.Black;
- this.button3.ForeColor = Color.White;
- this.button1.BackColor = Color.White;
- this.button1.ForeColor = Color.Black;
- this.button2.BackColor = Color.White;
- this.button2.ForeColor = Color.Black;
- }
- }
- /// <summary>
- /// 初始化hint提示信息
- /// </summary>
- private void InitializeHint()
- {
- SystemLayer.SafeNativeMethods.SetCueText(this.textBox1, PdnResources.GetString("Menu.Pleaseenterarulername.text"));
- SystemLayer.SafeNativeMethods.SetCueText(this.textBox2, PdnResources.GetString("Menu.Pleaseenterthemagnification.text"));
- SystemLayer.SafeNativeMethods.SetCueText(this.textBox4, PdnResources.GetString("Menu.Pleaseinputimageresolution.Text"));
- SystemLayer.SafeNativeMethods.SetCueText(this.textBox5, PdnResources.GetString("Menu.Pleaseenterthephysicallength.text"));
- SystemLayer.SafeNativeMethods.SetCueText(this.textBox6, PdnResources.GetString("Menu.Pixellength.text"));
- SystemLayer.SafeNativeMethods.SetCueText(this.textBox7, PdnResources.GetString("Menu.Pleaseentetionchanger.text"));
- SystemLayer.SafeNativeMethods.SetCueText(this.textBox8, PdnResources.GetString("Menu.Pleaseentertheinterface.text"));
- SystemLayer.SafeNativeMethods.SetCueText(this.textBox9, PdnResources.GetString("Menu.Pleaseentertheeyepiece.text"));
- SystemLayer.SafeNativeMethods.SetCueText(this.textBox10, PdnResources.GetString("Menu.Pleaseenterthecamera.text"));
- SystemLayer.SafeNativeMethods.SetCueText(this.textBox11, PdnResources.GetString("Menu.Pleaseenterobjectlens.text"));
- SystemLayer.SafeNativeMethods.SetCueText(this.textBox12, PdnResources.GetString("Menu.Pleaseenterthemicroscope.text"));
- }
- /// <summary>
- /// 第一步
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button1_Click(object sender, EventArgs e)
- {
- if (this.panel2.Visible || this.groupBox4.Visible)
- {
- this.groupBox3.Width = this.groupBox3.Width + this.groupBox4.Width + 3;
- }
- this.panel2.Visible = false;
- this.groupBox4.Visible = false;
- this.groupBox5.Visible = false;
- step = 1;
- InitializeUI();
- }
- /// <summary>
- /// 第二步
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button2_Click(object sender, EventArgs e)
- {
- if (bitmap==null) {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectrulerimage.Text")+"!");
- return;
- }
- if (!this.panel2.Visible && !this.groupBox4.Visible)
- {
- this.groupBox3.Width = this.groupBox3.Width - this.groupBox4.Width - 3;
- }
- this.panel2.Visible = true;
- this.groupBox4.Visible = false;
- this.groupBox5.Visible = false;
- this.button4.Text = PdnResources.GetString("Menu.Openimage.text");
- step = 2;
- InitializeUI();
- }
- /// <summary>
- /// 第三步
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button3_Click(object sender, EventArgs e)
- {
- if (bitmap == null)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectrulerimage.Text")+"!");
- return;
- }
- if (!this.panel2.Visible && !this.groupBox4.Visible)
- {
- this.groupBox3.Width = this.groupBox3.Width - this.groupBox4.Width - 3;
- }
- this.panel2.Visible = false;
- this.groupBox4.Visible = true;
- this.groupBox5.Visible = true;
- step = 3;
- InitializeUI();
- }
- /// <summary>
- /// 颜色选择
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void panel1_MouseDown(object sender, MouseEventArgs e)
- {
- this.colorsForm1.UserPrimaryColor = ColorBgra.FromColor(this.panel1.BackColor);
-
- this.colorsForm1.ShowDialog();
- }
-
- /// <summary>
- /// 水平方向
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button7_Click(object sender, EventArgs e)
- {
- direction = 1;
- RemoveDocEvent();
- AddPictureBoxEvent();
- }
- /// <summary>
- /// 垂直方向
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button8_Click(object sender, EventArgs e)
- {
- direction = 2;
- RemoveDocEvent();
- AddPictureBoxEvent();
- }
- /// <summary>
- /// 任意方向
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void button9_Click(object sender, EventArgs e)
- {
- direction = 3;
- RemoveDocEvent();
- AddPictureBoxEvent();
- }
- /// <summary>
- /// 添加事件
- /// </summary>
- private void AddPictureBoxEvent()
- {
- this.documentWorkspace.panel.MouseDown += new MouseEventHandler(this.BoxMouseDownHandler);
- this.documentWorkspace.panel.MouseMove += new MouseEventHandler(this.BoxMouseMoveHandler);
- this.documentWorkspace.panel.MouseUp += new MouseEventHandler(this.BoxMouseUpHandler);
- this.documentWorkspace.panel.Paint += new PaintEventHandler(this.BoxPaintHandler);
- }
- /// <summary>
- /// 绘制事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BoxPaintHandler(object sender, PaintEventArgs e)
- {
- if (startPoint!=null && endPoint!=null)
- {
- Rectangle rc = this.documentWorkspace.panel.ClientRectangle;
- int width1 = (int)(this.documentWorkspace.CompositionSurface.Width * this.documentWorkspace.ScaleFactor.Ratio);
- int height1 = (int)(this.documentWorkspace.CompositionSurface.Height * this.documentWorkspace.ScaleFactor.Ratio);
- int x = (rc.Width < width1) ? this.documentWorkspace.panel.AutoScrollPosition.X : (rc.Width - width1) / 2;
- int y = (rc.Height < height1) ? this.documentWorkspace.panel.AutoScrollPosition.Y : (rc.Height - height1) / 2;
- double length = BasicCalculationHelper.GetDistance(startPoint, endPoint, 2);
- e.Graphics.TranslateTransform(x, y);
- e.Graphics.ScaleTransform((float)this.documentWorkspace.ScaleFactor.Ratio, (float)this.documentWorkspace.ScaleFactor.Ratio);
- Pen linePen = new Pen(this.panel1.BackColor);
- brush = new SolidBrush(this.panel1.BackColor);
- linePen.Width = width;
- linePen.CustomStartCap = HookCap;
- linePen.CustomEndCap = HookCap;
- e.Graphics.DrawLine(linePen, startPoint, endPoint);
- linePen.Dispose();
- //参考下,然后绘制带角度的文字https://www.jianshu.com/p/404ed85887e6
- if (length > 0)
- {
- //计算需要旋转的角度
- double angle = BasicCalculationHelper.Angle(startPoint, endPoint, new System.Drawing.Point(startPoint.X, endPoint.Y));
-
- //原始旋转矩阵
- Matrix mtxSave = e.Graphics.Transform;
-
- Matrix matrix = e.Graphics.Transform;
-
- matrix.RotateAt((float)angle, new PointF(startPoint.X, startPoint.Y));
- e.Graphics.Transform = matrix;
- e.Graphics.DrawString(length + "px", font, brush, startPoint.X, startPoint.Y);
- //还原为原始旋转矩阵
- e.Graphics.Transform = mtxSave;
- this.textBox6.Text = length.ToString();//将像素长度传递至第三步
- }
- e.Graphics.ScaleTransform(1 / (float)this.documentWorkspace.ScaleFactor.Ratio, 1 / (float)this.documentWorkspace.ScaleFactor.Ratio);
- e.Graphics.TranslateTransform(-x, -y);
- }
- }
- private void BoxMouseUpHandler(object sender, MouseEventArgs e)
- {
- this.pressFlag = false;
- if (e.Button == MouseButtons.Left)
- direction = 0;
- }
- private void BoxMouseMoveHandler(object sender, MouseEventArgs e)
- {
- if (this.bitmap != null)
- {
- this.SetImageAndData(this.documentWorkspace.CalcPixelPoint(e.Location));
- }
- if (this.pressFlag && direction > 0 && e.Button == MouseButtons.Left) {
- System.Drawing.Point point = e.Location;
- if (direction == 1)
- {
- point.Y = y;
-
- }
- else if (direction == 2)
- {
- point.X = x;
- }
- this.endPoint = this.documentWorkspace.GetScalePoint(point);
- this.documentWorkspace.Refresh();
- }
- }
- private void numericUpDown2_ValueChanged(object sender, EventArgs e)
- {
- if (mat != null)
- {
- scale = (int)this.numericUpDown2.Value;
- this.trackBar1.Value = scale;
- }
- }
- private void trackBar1_ValueChanged(object sender, EventArgs e)
- {
- if (mat != null)
- {
- scale = this.trackBar1.Value;
- this.numericUpDown2.Value = this.trackBar1.Value;
- }
- }
- private void numericUpDown3_ValueChanged(object sender, EventArgs e)
- {
- font = new Font("常规", (int)this.numericUpDown3.Value);
- this.documentWorkspace.Refresh();
- }
- private void pictureBox1_Paint(object sender, PaintEventArgs e)
- {
- e.Graphics.DrawLine(new Pen(color), 0, 50, 100, 50);
- e.Graphics.DrawLine(new Pen(color), 50, 0, 50, 100);
- e.Graphics.DrawEllipse(new Pen(color), new Rectangle(25, 25, 50, 50));
- }
- private void BoxMouseDownHandler(object sender, MouseEventArgs e)
- {
- this.pressFlag = true;
- if (direction > 0 && e.Button == MouseButtons.Left) {
- x = e.Location.X;
- y = e.Location.Y;
- startPoint = endPoint = this.documentWorkspace.GetScalePoint(e.Location);
- }
- }
- private void numericUpDown1_ValueChanged(object sender, EventArgs e)
- {
- this.width = (int)this.numericUpDown1.Value;
- this.documentWorkspace.Refresh();
- }
- private void RemoveDocEvent()
- {
- this.documentWorkspace.DocumentMouseUp -= new MouseEventHandler(this.MouseUpHandler);
- this.documentWorkspace.DocumentMouseMove -= new MouseEventHandler(this.MouseMoveHandler);
- this.documentWorkspace.DocumentMouseDown -= new MouseEventHandler(this.MouseDownHandler);
- }
- /// <summary>
- /// 设置像素跟踪
- /// </summary>
- /// <param name="point"></param>
- public void SetImageAndData(System.Drawing.Point point)
- {
- if (this.documentWorkspace != null)
- {
- if (this.documentWorkspace.CompositionSurface != null)
- {
- scale = int.Parse(this.numericUpDown2.Value.ToString());
- if (mat == null)
- {
- mat = this.documentWorkspace.CompositionSurface.CreatedAliasedMat().Clone();
- Cv2.Resize(mat, bmat, new OpenCvSharp.Size(mat.Width * scale, mat.Height * scale));
- Mat temp = new Mat(new OpenCvSharp.Size(bmat.Width + 100, bmat.Height + 100), bmat.Type());
- Cv2.CopyMakeBorder(bmat, temp, 50, 50, 50, 50, BorderTypes.Constant, Scalar.All(255));
- bmat = temp;
- }
- if (point.Y < 0) point.Y = 0;
- if (point.X < 0) point.X = 0;
- this.label11.Text = "X=" + point.X.ToString();
- this.label10.Text = "Y=" + point.Y.ToString();
- if (point.X< mat.Width && point.Y < mat.Height)
- {
- bgr = mat.At<Vec3b>(point.Y, point.X);
- this.label8.Text = "R=" + bgr[2];
- this.label2.Text = "G=" + bgr[1];
- this.label3.Text = "B=" + bgr[0];
- BaseTools.RgbToHsv(bgr, out h, out s, out v);
- this.label4.Text = "H=" + (int)(h / 2);
- this.label5.Text = "S=" + (int)(s * 255);
- this.label6.Text = "V=" + (int)(v * 255);
- //设置源图像ROI
- Rect roi = new Rect(point.X, point.Y, 100, 100);//首先要用个rect确定我们的兴趣区域在哪
- ImageROI = new Mat(bmat, roi);
- //按缩放比例截取小图像
- Rect roi1 = new Rect((100 - 100 / scale) / 2, (100 - 100 / scale) / 2, 100 / scale, 100 / scale);
- ImageROI = new Mat(ImageROI, roi1);
- //按固定宽高放大图像
- Cv2.Resize(ImageROI, ImageROI, new OpenCvSharp.Size(100, 100));
- this.pictureBox1.Image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(ImageROI);
- }
- }
- }
- }
- }
- }
|