123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496 |
- 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
- {
- /// <summary>
- /// 分栏显示
- /// </summary>
- 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;
- /// <summary>
- /// 自定义控件
- /// </summary>
- ColControl colControl1, colControl2, colControl3, colControl4, colControl5, colControl6, colControl7,
- colControl8, colControl9;
- /// <summary>
- /// 自定义控件的list
- /// </summary>
- List<ColControl> listColControl;
- /// <summary>
- /// 图像显示数量下拉选项
- /// </summary>
- int[] imgCount = new int[] { 2, 3, 4, 6, 8, 9 };
- /// <summary>
- /// 调色板
- /// </summary>
- PaintDotNet.ColorsForm colorsForm;
- /// <summary>
- /// 图片选择窗口
- /// </summary>
- private InterImagePickerDialog imagePickerDialog;
- /// <summary>
- /// 图片
- /// </summary>
- Bitmap newBitmap;
- /// <summary>
- /// 辅助判断操作的是哪个按钮
- /// </summary>
- private int buttonNum = 0;
- /// <summary>
- /// 辅助判断操作的是哪个自定义控件
- /// </summary>
- private int colNum = 0;
- /// <summary>
- /// picturebox中缩略图与原始图片宽度比例
- /// </summary>
- private double widthRatio;
- /// <summary>
- /// picturebox中缩略图与原始图片高度比例
- /// </summary>
- private double heightRatio;
- /// <summary>
- /// 算偏移量使用
- /// </summary>
- Point lastPoint = new Point(0, 0);
- /// <summary>
- /// picturebox中的图片矩形
- /// </summary>
- Rectangle imageRect;
- /// <summary>
- /// picturebox中的小矩形框
- /// </summary>
- Rectangle zoomRect;
- /// <summary>
- /// 判断是否要重新计算picturebox的矩形
- /// </summary>
- bool isFirst = true;
- /// <summary>
- /// 鼠标move时是否为拖动矩形框
- /// </summary>
- bool isSelected = false;
- /// <summary>
- /// 鼠标move时是否为修改矩形大小
- /// </summary>
- bool isResized = false;
- /// <summary>
- /// 临时使用的自定义控件对象
- /// </summary>
- ColControl newColtrol = null;
- /// <summary>
- /// picturebox中红框的最小宽度(原图放大3200%)
- /// </summary>
- private int minRectWidth;
- /// <summary>
- /// picturebox中红框的最小高度(原图放大3200%)
- /// </summary>
- private int minRectHeight;
- /// <summary>
- /// 步长
- /// </summary>
- 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<ColControl>();
- 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();
- }
- /// <summary>
- /// 根据下拉菜单选择的图片数量刷新pannel
- /// </summary>
- 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);
- }
- /// <summary>
- /// 绑定其他数据
- /// </summary>
- 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);
- }
- /// <summary>
- /// 下拉菜单选项改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
- {
- InitializeColControls();
- this.panel1.Refresh();
- lastPoint.X = 0;
- lastPoint.Y = 0;
- refreshRectangle();
- }
- /// <summary>
- /// 选中控件的边框
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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();
- }
- /// <summary>
- /// textbox限制输入数字
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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)
- {
- }
- /// <summary>
- /// 缩略图的鼠标按下事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
- {
- lastPoint.X = e.X;
- lastPoint.Y = e.Y;
- //是否平移
- if (zoomRect.Contains(e.Location) && !new Rectangle((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;
- }
- }
- /// <summary>
- /// 缩略图的鼠标拖动事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
- {
- this.pictureBox1.Cursor = Cursors.Default;
- if (zoomRect != null)
- {
- if (zoomRect.Contains(e.Location) && !new Rectangle((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();
- }
- /// <summary>
- /// 合并并创建图片
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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"));
- }
- }
- /// <summary>
- /// 创建新图片
- /// </summary>
- /// <param name="mat"></param>
- 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;
- }
- }
- /// <summary>
- /// 拼接图片
- /// </summary>
- /// <param name="bitmaps"></param>
- /// <param name="onePicWidth"></param>
- /// <param name="onePicHeight"></param>
- /// <returns></returns>
- 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;
- }
- }
- /// <summary>
- /// 获取按比例缩放的图片
- /// </summary>
- /// <param name="bit"></param>
- /// <param name="ratio"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 把小图拼到一起
- /// </summary>
- /// <param name="bmp"></param>
- /// <param name="bitmaps"></param>
- /// <param name="onePicWidth"></param>
- /// <param name="onePicHeight"></param>
- /// <returns></returns>
- 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();
- }
- /// <summary>
- /// 窗口大小改变
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void panel1_Resize(object sender, EventArgs e)
- {
- lastPoint.X = 0;
- lastPoint.Y = 0;
- RefreshColcontrol();
- refreshRectangle();
- }
- /// <summary>
- /// 刷新picture的矩形框
- /// </summary>
- 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();
- }
- }
- /// <summary>
- /// 通过document窗口与图片计算显示比例
- /// </summary>
- /// <param name="colControl"></param>
- 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;
- }
- }
- /// <summary>
- /// 点击图库按钮
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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();
- }
- }
- }
- /// <summary>
- /// 从图库选择待对照图片
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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;
- }
- /// <summary>
- /// 点击自定义控件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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;
- }
- }
- /// <summary>
- /// picturebox绘制矩形选中区域
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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();
- }
- }
- /// <summary>
- /// 移动滚动条改变picture矩形框位置
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- 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();
- }
- }
- /// <summary>
- /// 从大图中截取一部分图片
- /// </summary>
- /// <param name="fromImage">来源图片</param>
- /// <param name="offsetX">从偏移X坐标位置开始截取</param>
- /// <param name="offsetY">从偏移Y坐标位置开始截取</param>
- /// <param name="width">保存图片的宽度</param>
- /// <param name="height">保存图片的高度</param>
- /// <returns></returns>
- 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();
- }
- }
- }
|