12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495 |
- 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.FromImage(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.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();
- }
- }
- }
|