ColumnsShowDialog.cs 121 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495
  1. using OpenCvSharp.Extensions;
  2. using PaintDotNet.Instrument.CustomInterface;
  3. using PaintDotNet.Processing;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Data.Entity.Migrations.Model;
  9. using System.Drawing;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Reflection;
  13. using System.Runtime.Serialization.Formatters.Binary;
  14. using System.Security.Policy;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using System.Windows.Forms;
  18. namespace PaintDotNet.Instrument
  19. {
  20. /// <summary>
  21. /// 分栏显示
  22. /// </summary>
  23. internal class ColumnsShowDialog : PdnBaseForm
  24. {
  25. private GroupBox groupBox1;
  26. private Panel panel1;
  27. private GroupBox groupBox2;
  28. private GroupBox groupBox3;
  29. private Label label1;
  30. private Label label4;
  31. private Panel panel2;
  32. private Label label3;
  33. private Label label2;
  34. private TextBox textBox1;
  35. private ComboBox comboBox1;
  36. private Panel panel3;
  37. private CheckBox checkBox1;
  38. private Button button1;
  39. private TextBox textBox2;
  40. private PictureBox pictureBox1;
  41. private AppWorkspace appWorkspace;
  42. /// <summary>
  43. /// 自定义控件
  44. /// </summary>
  45. ColControl colControl1, colControl2, colControl3, colControl4, colControl5, colControl6, colControl7,
  46. colControl8, colControl9;
  47. /// <summary>
  48. /// 自定义控件的list
  49. /// </summary>
  50. List<ColControl> listColControl;
  51. /// <summary>
  52. /// 图像显示数量下拉选项
  53. /// </summary>
  54. int[] imgCount = new int[] { 2, 3, 4, 6, 8, 9 };
  55. /// <summary>
  56. /// 调色板
  57. /// </summary>
  58. PaintDotNet.ColorsForm colorsForm;
  59. /// <summary>
  60. /// 图片选择窗口
  61. /// </summary>
  62. private InterImagePickerDialog imagePickerDialog;
  63. /// <summary>
  64. /// 图片
  65. /// </summary>
  66. Bitmap newBitmap;
  67. /// <summary>
  68. /// 辅助判断操作的是哪个按钮
  69. /// </summary>
  70. private int buttonNum = 0;
  71. /// <summary>
  72. /// 辅助判断操作的是哪个自定义控件
  73. /// </summary>
  74. private int colNum = 0;
  75. /// <summary>
  76. /// picturebox中缩略图与原始图片宽度比例
  77. /// </summary>
  78. private double widthRatio;
  79. /// <summary>
  80. /// picturebox中缩略图与原始图片高度比例
  81. /// </summary>
  82. private double heightRatio;
  83. /// <summary>
  84. /// 算偏移量使用
  85. /// </summary>
  86. Point lastPoint = new Point(0, 0);
  87. /// <summary>
  88. /// picturebox中的图片矩形
  89. /// </summary>
  90. Rectangle imageRect;
  91. /// <summary>
  92. /// picturebox中的小矩形框
  93. /// </summary>
  94. Rectangle zoomRect;
  95. /// <summary>
  96. /// 判断是否要重新计算picturebox的矩形
  97. /// </summary>
  98. bool isFirst = true;
  99. /// <summary>
  100. /// 鼠标move时是否为拖动矩形框
  101. /// </summary>
  102. bool isSelected = false;
  103. /// <summary>
  104. /// 鼠标move时是否为修改矩形大小
  105. /// </summary>
  106. bool isResized = false;
  107. /// <summary>
  108. /// 临时使用的自定义控件对象
  109. /// </summary>
  110. ColControl newColtrol = null;
  111. /// <summary>
  112. /// picturebox中红框的最小宽度(原图放大3200%)
  113. /// </summary>
  114. private int minRectWidth;
  115. /// <summary>
  116. /// picturebox中红框的最小高度(原图放大3200%)
  117. /// </summary>
  118. private int minRectHeight;
  119. /// <summary>
  120. /// 步长
  121. /// </summary>
  122. string stepLength = "00" + Startup.instance.step_length;
  123. int imgWidth = 0;
  124. int imgHeight = 0;
  125. public ColumnsShowDialog(AppWorkspace appWorkspace)
  126. {
  127. this.appWorkspace = appWorkspace;
  128. colControl1 = new ColControl();
  129. colControl2 = new ColControl();
  130. colControl3 = new ColControl();
  131. colControl4 = new ColControl();
  132. colControl5 = new ColControl();
  133. colControl6 = new ColControl();
  134. colControl7 = new ColControl();
  135. colControl8 = new ColControl();
  136. colControl9 = new ColControl();
  137. listColControl = new List<ColControl>();
  138. listColControl.Add(colControl1);
  139. listColControl.Add(colControl2);
  140. listColControl.Add(colControl3);
  141. listColControl.Add(colControl4);
  142. listColControl.Add(colControl5);
  143. listColControl.Add(colControl6);
  144. listColControl.Add(colControl7);
  145. listColControl.Add(colControl8);
  146. listColControl.Add(colControl9);
  147. for (int i = 0; i < listColControl.Count; i++)
  148. {
  149. listColControl[i].button.Tag = (i + 1);
  150. listColControl[i].button.Click += new EventHandler(ColControl_Click);
  151. listColControl[i].Tag = (i + 1);
  152. listColControl[i].Click += new EventHandler(ColControl_Click);
  153. listColControl[i].workspaceWindow.panel.Tag = (i + 1);
  154. listColControl[i].workspaceWindow.panel.MouseDown += ColControl_Click;
  155. listColControl[i].workspaceWindow.leftRuler.Tag = (i + 1);
  156. listColControl[i].workspaceWindow.leftRuler.MouseDown += ColControl_Click;
  157. listColControl[i].workspaceWindow.topRuler.Tag = (i + 1);
  158. listColControl[i].workspaceWindow.topRuler.MouseDown += ColControl_Click;
  159. listColControl[i].workspaceWindow.panel.Scroll += new ScrollEventHandler(scrollMovePictureBox);
  160. }
  161. InitializeComponent();
  162. InitializeLanguageText();
  163. InitializeControlData();
  164. InitializeColControls();
  165. }
  166. /// <summary>
  167. /// 根据下拉菜单选择的图片数量刷新pannel
  168. /// </summary>
  169. private void InitializeColControls()
  170. {
  171. this.panel1.Controls.Clear();
  172. RefreshColcontrol();
  173. }
  174. private void RefreshColcontrol()
  175. {
  176. int controlCount = imgCount[this.comboBox1.SelectedIndex];
  177. switch (controlCount)
  178. {
  179. case 2:
  180. colControl1.Size = new Size(this.panel1.Width / 2 - 4, this.panel1.Height - 4);
  181. colControl1.Location = new Point(2, 2);
  182. this.panel1.Controls.Add(colControl1);
  183. colControl2.Size = new Size(this.panel1.Width / 2 - 4, this.panel1.Height - 4);
  184. colControl2.Location = new Point(this.panel1.Width / 2 + 2, 2);
  185. this.panel1.Controls.Add(colControl2);
  186. break;
  187. case 3:
  188. colControl1.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height - 4);
  189. colControl1.Location = new Point(2, 2);
  190. this.panel1.Controls.Add(colControl1);
  191. colControl2.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height - 4);
  192. colControl2.Location = new Point(this.panel1.Width / 3 + 2, 2);
  193. this.panel1.Controls.Add(colControl2);
  194. colControl3.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height - 4);
  195. colControl3.Location = new Point(this.panel1.Width / 3 * 2 + 2, 2);
  196. this.panel1.Controls.Add(colControl3);
  197. break;
  198. case 4:
  199. colControl1.Size = new Size(this.panel1.Width / 2 - 4, this.panel1.Height / 2 - 4);
  200. colControl1.Location = new Point(2, 2);
  201. this.panel1.Controls.Add(colControl1);
  202. colControl2.Size = new Size(this.panel1.Width / 2 - 4, this.panel1.Height / 2 - 4);
  203. colControl2.Location = new Point(this.panel1.Width / 2 + 2, 2);
  204. this.panel1.Controls.Add(colControl2);
  205. colControl3.Size = new Size(this.panel1.Width / 2 - 4, this.panel1.Height / 2 - 4);
  206. colControl3.Location = new Point(2, this.panel1.Height / 2 + 2);
  207. this.panel1.Controls.Add(colControl3);
  208. colControl4.Size = new Size(this.panel1.Width / 2 - 4, this.panel1.Height / 2 - 4);
  209. colControl4.Location = new Point(this.panel1.Width / 2 + 2, this.panel1.Height / 2 + 2);
  210. this.panel1.Controls.Add(colControl4);
  211. break;
  212. case 6:
  213. colControl1.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 2 - 4);
  214. colControl1.Location = new Point(2, 2);
  215. this.panel1.Controls.Add(colControl1);
  216. colControl2.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 2 - 4);
  217. colControl2.Location = new Point(this.panel1.Width / 3 + 2, 2);
  218. this.panel1.Controls.Add(colControl2);
  219. colControl3.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 2 - 4);
  220. colControl3.Location = new Point(this.panel1.Width / 3 * 2 + 2, 2);
  221. this.panel1.Controls.Add(colControl3);
  222. colControl4.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 2 - 4);
  223. colControl4.Location = new Point(2, this.panel1.Height / 2 + 2);
  224. this.panel1.Controls.Add(colControl4);
  225. colControl5.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 2 - 4);
  226. colControl5.Location = new Point(this.panel1.Width / 3 + 2, this.panel1.Height / 2 + 2);
  227. this.panel1.Controls.Add(colControl5);
  228. colControl6.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 2 - 4);
  229. colControl6.Location = new Point(this.panel1.Width / 3 * 2 + 2, this.panel1.Height / 2 + 2);
  230. this.panel1.Controls.Add(colControl6);
  231. break;
  232. case 8:
  233. colControl1.Size = new Size(this.panel1.Width / 4 - 4, this.panel1.Height / 2 - 4);
  234. colControl1.Location = new Point(2, 2);
  235. this.panel1.Controls.Add(colControl1);
  236. colControl2.Size = new Size(this.panel1.Width / 4 - 4, this.panel1.Height / 2 - 4);
  237. colControl2.Location = new Point(this.panel1.Width / 4 + 2, 2);
  238. this.panel1.Controls.Add(colControl2);
  239. colControl3.Size = new Size(this.panel1.Width / 4 - 4, this.panel1.Height / 2 - 4);
  240. colControl3.Location = new Point(this.panel1.Width / 4 * 2 + 2, 2);
  241. this.panel1.Controls.Add(colControl3);
  242. colControl4.Size = new Size(this.panel1.Width / 4 - 4, this.panel1.Height / 2 - 4);
  243. colControl4.Location = new Point(this.panel1.Width / 4 * 3 + 2, 2);
  244. this.panel1.Controls.Add(colControl4);
  245. colControl5.Size = new Size(this.panel1.Width / 4 - 4, this.panel1.Height / 2 - 4);
  246. colControl5.Location = new Point(2, this.panel1.Height / 2 + 2);
  247. this.panel1.Controls.Add(colControl5);
  248. colControl6.Size = new Size(this.panel1.Width / 4 - 4, this.panel1.Height / 2 - 4);
  249. colControl6.Location = new Point(this.panel1.Width / 4 + 2, this.panel1.Height / 2 + 2);
  250. this.panel1.Controls.Add(colControl6);
  251. colControl7.Size = new Size(this.panel1.Width / 4 - 4, this.panel1.Height / 2 - 4);
  252. colControl7.Location = new Point(this.panel1.Width / 4 * 2 + 2, this.panel1.Height / 2 + 2);
  253. this.panel1.Controls.Add(colControl7);
  254. colControl8.Size = new Size(this.panel1.Width / 4 - 4, this.panel1.Height / 2 - 4);
  255. colControl8.Location = new Point(this.panel1.Width / 4 * 3 + 2, this.panel1.Height / 2 + 2);
  256. this.panel1.Controls.Add(colControl8);
  257. break;
  258. case 9:
  259. colControl1.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 3 - 4);
  260. colControl1.Location = new Point(2, 2);
  261. this.panel1.Controls.Add(colControl1);
  262. colControl2.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 3 - 4);
  263. colControl2.Location = new Point(this.panel1.Width / 3 + 2, 2);
  264. this.panel1.Controls.Add(colControl2);
  265. colControl3.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 3 - 4);
  266. colControl3.Location = new Point(this.panel1.Width / 3 * 2 + 2, 2);
  267. this.panel1.Controls.Add(colControl3);
  268. colControl4.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 3 - 4);
  269. colControl4.Location = new Point(2, this.panel1.Height / 3 + 2);
  270. this.panel1.Controls.Add(colControl4);
  271. colControl5.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 3 - 4);
  272. colControl5.Location = new Point(this.panel1.Width / 3 + 2, this.panel1.Height / 3 + 2);
  273. this.panel1.Controls.Add(colControl5);
  274. colControl6.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 3 - 4);
  275. colControl6.Location = new Point(this.panel1.Width / 3 * 2 + 2, this.panel1.Height / 3 + 2);
  276. this.panel1.Controls.Add(colControl6);
  277. colControl7.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 3 - 4);
  278. colControl7.Location = new Point(2, this.panel1.Height / 3 * 2 + 2);
  279. this.panel1.Controls.Add(colControl7);
  280. colControl8.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 3 - 4);
  281. colControl8.Location = new Point(this.panel1.Width / 3 + 2, this.panel1.Height / 3 * 2 + 2);
  282. this.panel1.Controls.Add(colControl8);
  283. colControl9.Size = new Size(this.panel1.Width / 3 - 4, this.panel1.Height / 3 - 4);
  284. colControl9.Location = new Point(this.panel1.Width / 3 * 2 + 2, this.panel1.Height / 3 * 2 + 2);
  285. this.panel1.Controls.Add(colControl9);
  286. break;
  287. }
  288. }
  289. private void InitializeLanguageText()
  290. {
  291. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  292. this.button1.Text = PdnResources.GetString("Menu.Createpicture.text");
  293. this.groupBox2.Text = PdnResources.GetString("Menu.Setting.Text");
  294. this.label4.Text = PdnResources.GetString("Menu.tool.Columndisplay.Numberofimages.text") + ":";
  295. this.label3.Text = PdnResources.GetString("Menu.tool.Columndisplay.Columncolor.text") + ":";
  296. this.label2.Text = PdnResources.GetString("Menu.Pixel.text");
  297. this.label1.Text = PdnResources.GetString("Menu.tool.Columndisplay.imagespacing.text") + ":";
  298. this.groupBox3.Text = PdnResources.GetString("Menu.tool.Columndisplay.Thumbnail.text");
  299. this.checkBox1.Text = PdnResources.GetString("Menu.tool.Columndisplay.synchronousmode.text");
  300. this.Text = PdnResources.GetString("Menu.Tools.ColumnDisplay.Text");
  301. }
  302. private void InitializeComponent()
  303. {
  304. this.groupBox1 = new System.Windows.Forms.GroupBox();
  305. this.button1 = new System.Windows.Forms.Button();
  306. this.panel1 = new System.Windows.Forms.Panel();
  307. this.groupBox2 = new System.Windows.Forms.GroupBox();
  308. this.comboBox1 = new System.Windows.Forms.ComboBox();
  309. this.label4 = new System.Windows.Forms.Label();
  310. this.panel2 = new System.Windows.Forms.Panel();
  311. this.label3 = new System.Windows.Forms.Label();
  312. this.label2 = new System.Windows.Forms.Label();
  313. this.textBox1 = new System.Windows.Forms.TextBox();
  314. this.label1 = new System.Windows.Forms.Label();
  315. this.groupBox3 = new System.Windows.Forms.GroupBox();
  316. this.checkBox1 = new System.Windows.Forms.CheckBox();
  317. this.panel3 = new System.Windows.Forms.Panel();
  318. this.textBox2 = new System.Windows.Forms.TextBox();
  319. this.pictureBox1 = new System.Windows.Forms.PictureBox();
  320. this.groupBox1.SuspendLayout();
  321. this.groupBox2.SuspendLayout();
  322. this.groupBox3.SuspendLayout();
  323. this.panel3.SuspendLayout();
  324. ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
  325. this.SuspendLayout();
  326. //
  327. // groupBox1
  328. //
  329. this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  330. | System.Windows.Forms.AnchorStyles.Right)));
  331. this.groupBox1.Controls.Add(this.button1);
  332. this.groupBox1.Location = new System.Drawing.Point(13, 13);
  333. this.groupBox1.Name = "groupBox1";
  334. this.groupBox1.Size = new System.Drawing.Size(784, 55);
  335. this.groupBox1.TabIndex = 0;
  336. this.groupBox1.TabStop = false;
  337. this.groupBox1.Text = "操作";
  338. //
  339. // button1
  340. //
  341. this.button1.Anchor = System.Windows.Forms.AnchorStyles.Right;
  342. this.button1.Location = new System.Drawing.Point(678, 20);
  343. this.button1.Name = "button1";
  344. this.button1.Size = new System.Drawing.Size(75, 23);
  345. this.button1.TabIndex = 0;
  346. this.button1.Text = "创建图片";
  347. this.button1.UseVisualStyleBackColor = true;
  348. this.button1.Click += new System.EventHandler(this.button1_Click);
  349. //
  350. // panel1
  351. //
  352. this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  353. | System.Windows.Forms.AnchorStyles.Left)
  354. | System.Windows.Forms.AnchorStyles.Right)));
  355. this.panel1.BackColor = System.Drawing.SystemColors.Control;
  356. this.panel1.Location = new System.Drawing.Point(13, 84);
  357. this.panel1.Name = "panel1";
  358. this.panel1.Size = new System.Drawing.Size(589, 590);
  359. this.panel1.TabIndex = 1;
  360. this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
  361. this.panel1.Resize += new System.EventHandler(this.panel1_Resize);
  362. //
  363. // groupBox2
  364. //
  365. this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  366. this.groupBox2.Controls.Add(this.comboBox1);
  367. this.groupBox2.Controls.Add(this.label4);
  368. this.groupBox2.Controls.Add(this.panel2);
  369. this.groupBox2.Controls.Add(this.label3);
  370. this.groupBox2.Controls.Add(this.label2);
  371. this.groupBox2.Controls.Add(this.textBox1);
  372. this.groupBox2.Controls.Add(this.label1);
  373. this.groupBox2.Location = new System.Drawing.Point(608, 84);
  374. this.groupBox2.Name = "groupBox2";
  375. this.groupBox2.Size = new System.Drawing.Size(189, 186);
  376. this.groupBox2.TabIndex = 2;
  377. this.groupBox2.TabStop = false;
  378. this.groupBox2.Text = "设置";
  379. //
  380. // comboBox1
  381. //
  382. this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  383. this.comboBox1.FormattingEnabled = true;
  384. this.comboBox1.Location = new System.Drawing.Point(61, 124);
  385. this.comboBox1.Name = "comboBox1";
  386. this.comboBox1.Size = new System.Drawing.Size(110, 20);
  387. this.comboBox1.TabIndex = 6;
  388. this.comboBox1.SelectionChangeCommitted += new System.EventHandler(this.comboBox1_SelectionChangeCommitted);
  389. //
  390. // label4
  391. //
  392. this.label4.AutoSize = true;
  393. this.label4.Location = new System.Drawing.Point(-2, 127);
  394. this.label4.Name = "label4";
  395. this.label4.Size = new System.Drawing.Size(65, 12);
  396. this.label4.TabIndex = 5;
  397. this.label4.Text = "图片数量:";
  398. //
  399. // panel2
  400. //
  401. this.panel2.BackColor = System.Drawing.Color.Red;
  402. this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  403. this.panel2.Location = new System.Drawing.Point(61, 75);
  404. this.panel2.Name = "panel2";
  405. this.panel2.Size = new System.Drawing.Size(110, 20);
  406. this.panel2.TabIndex = 4;
  407. this.panel2.Click += new System.EventHandler(this.panel2_Click);
  408. //
  409. // label3
  410. //
  411. this.label3.AutoSize = true;
  412. this.label3.Location = new System.Drawing.Point(-2, 79);
  413. this.label3.Name = "label3";
  414. this.label3.Size = new System.Drawing.Size(65, 12);
  415. this.label3.TabIndex = 3;
  416. this.label3.Text = "分栏颜色:";
  417. //
  418. // label2
  419. //
  420. this.label2.AutoSize = true;
  421. this.label2.Location = new System.Drawing.Point(142, 28);
  422. this.label2.Name = "label2";
  423. this.label2.Size = new System.Drawing.Size(29, 12);
  424. this.label2.TabIndex = 2;
  425. this.label2.Text = "像素";
  426. //
  427. // textBox1
  428. //
  429. this.textBox1.Location = new System.Drawing.Point(61, 25);
  430. this.textBox1.Name = "textBox1";
  431. this.textBox1.Size = new System.Drawing.Size(75, 21);
  432. this.textBox1.TabIndex = 1;
  433. this.textBox1.Text = "0";
  434. this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);
  435. //
  436. // label1
  437. //
  438. this.label1.AutoSize = true;
  439. this.label1.Location = new System.Drawing.Point(-2, 28);
  440. this.label1.Name = "label1";
  441. this.label1.Size = new System.Drawing.Size(65, 12);
  442. this.label1.TabIndex = 0;
  443. this.label1.Text = "图片间距:";
  444. //
  445. // groupBox3
  446. //
  447. this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  448. this.groupBox3.Controls.Add(this.checkBox1);
  449. this.groupBox3.Controls.Add(this.panel3);
  450. this.groupBox3.Location = new System.Drawing.Point(608, 270);
  451. this.groupBox3.Name = "groupBox3";
  452. this.groupBox3.Size = new System.Drawing.Size(189, 213);
  453. this.groupBox3.TabIndex = 3;
  454. this.groupBox3.TabStop = false;
  455. this.groupBox3.Text = "缩略图";
  456. //
  457. // checkBox1
  458. //
  459. this.checkBox1.AutoSize = true;
  460. this.checkBox1.Location = new System.Drawing.Point(8, 182);
  461. this.checkBox1.Name = "checkBox1";
  462. this.checkBox1.Size = new System.Drawing.Size(72, 16);
  463. this.checkBox1.TabIndex = 1;
  464. this.checkBox1.Text = "同步方式";
  465. this.checkBox1.UseVisualStyleBackColor = true;
  466. //
  467. // panel3
  468. //
  469. this.panel3.Controls.Add(this.textBox2);
  470. this.panel3.Controls.Add(this.pictureBox1);
  471. this.panel3.Location = new System.Drawing.Point(8, 20);
  472. this.panel3.Name = "panel3";
  473. this.panel3.Size = new System.Drawing.Size(163, 147);
  474. this.panel3.TabIndex = 0;
  475. //
  476. // textBox2
  477. //
  478. this.textBox2.BackColor = System.Drawing.SystemColors.Control;
  479. this.textBox2.Location = new System.Drawing.Point(40, 123);
  480. this.textBox2.Name = "textBox2";
  481. this.textBox2.ReadOnly = true;
  482. this.textBox2.Size = new System.Drawing.Size(88, 21);
  483. this.textBox2.TabIndex = 1;
  484. this.textBox2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
  485. //
  486. // pictureBox1
  487. //
  488. this.pictureBox1.Location = new System.Drawing.Point(0, 0);
  489. this.pictureBox1.Name = "pictureBox1";
  490. this.pictureBox1.Size = new System.Drawing.Size(162, 122);
  491. this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
  492. this.pictureBox1.TabIndex = 0;
  493. this.pictureBox1.TabStop = false;
  494. this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
  495. this.pictureBox1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);
  496. //
  497. // ColumnsShowDialog
  498. //
  499. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  500. this.ClientSize = new System.Drawing.Size(809, 686);
  501. this.Controls.Add(this.groupBox3);
  502. this.Controls.Add(this.groupBox2);
  503. this.Controls.Add(this.panel1);
  504. this.Controls.Add(this.groupBox1);
  505. this.MinimizeBox = false;
  506. this.Name = "ColumnsShowDialog";
  507. this.Text = "分栏显示:";
  508. this.Controls.SetChildIndex(this.groupBox1, 0);
  509. this.Controls.SetChildIndex(this.panel1, 0);
  510. this.Controls.SetChildIndex(this.groupBox2, 0);
  511. this.Controls.SetChildIndex(this.groupBox3, 0);
  512. this.groupBox1.ResumeLayout(false);
  513. this.groupBox2.ResumeLayout(false);
  514. this.groupBox2.PerformLayout();
  515. this.groupBox3.ResumeLayout(false);
  516. this.groupBox3.PerformLayout();
  517. this.panel3.ResumeLayout(false);
  518. this.panel3.PerformLayout();
  519. ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
  520. this.ResumeLayout(false);
  521. }
  522. /// <summary>
  523. /// 绑定其他数据
  524. /// </summary>
  525. private void InitializeControlData()
  526. {
  527. //图片数量下拉菜单绑定
  528. this.comboBox1.DataSource = imgCount;
  529. this.comboBox1.SelectedIndex = 2;
  530. //调色板
  531. this.colorsForm = new ColorsForm();
  532. this.colorsForm.StartPosition = FormStartPosition.CenterScreen;
  533. this.colorsForm.UserPrimaryColorChanged += new ColorEventHandler(this.colorsFormUserPrimaryColorChanged);
  534. }
  535. /// <summary>
  536. /// 下拉菜单选项改变
  537. /// </summary>
  538. /// <param name="sender"></param>
  539. /// <param name="e"></param>
  540. private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
  541. {
  542. InitializeColControls();
  543. this.panel1.Refresh();
  544. lastPoint.X = 0;
  545. lastPoint.Y = 0;
  546. refreshRectangle();
  547. }
  548. /// <summary>
  549. /// 选中控件的边框
  550. /// </summary>
  551. /// <param name="sender"></param>
  552. /// <param name="e"></param>
  553. private void panel1_Paint(object sender, PaintEventArgs e)
  554. {
  555. Pen borderPen = new Pen(Color.Red, 5);//默认红色
  556. for (int i = 0; i < listColControl.Count; i++)
  557. {
  558. if (listColControl[i].isSelect)
  559. {
  560. e.Graphics.DrawRectangle(borderPen, listColControl[i].Location.X - 2, listColControl[i].Location.Y - 2,
  561. listColControl[i].Size.Width + 2, listColControl[i].Size.Height + 2);
  562. }
  563. }
  564. borderPen.Dispose();
  565. }
  566. /// <summary>
  567. /// textbox限制输入数字
  568. /// </summary>
  569. /// <param name="sender"></param>
  570. /// <param name="e"></param>
  571. private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
  572. {
  573. char kc = e.KeyChar;
  574. if ((kc < 48 || kc > 57) && kc != 8 && kc != 46)
  575. e.Handled = true;
  576. if (kc == 46) //小数点
  577. {
  578. if (this.textBox1.Text.Length <= 0)
  579. e.Handled = true; //小数点不能在第一位
  580. else
  581. {
  582. float f;
  583. float oldf;
  584. bool b1 = false, b2 = false;
  585. b1 = float.TryParse(this.textBox1.Text, out oldf);
  586. b2 = float.TryParse(this.textBox1.Text + e.KeyChar.ToString(), out f);
  587. if (b2 == false)
  588. {
  589. if (b1 == true)
  590. e.Handled = true;
  591. else
  592. e.Handled = false;
  593. }
  594. }
  595. }
  596. }
  597. private void colorsFormUserPrimaryColorChanged(object sender, ColorEventArgs ce)
  598. {
  599. }
  600. /// <summary>
  601. /// 缩略图的鼠标按下事件
  602. /// </summary>
  603. /// <param name="sender"></param>
  604. /// <param name="e"></param>
  605. private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
  606. {
  607. lastPoint.X = e.X;
  608. lastPoint.Y = e.Y;
  609. //是否平移
  610. if (zoomRect.Contains(e.Location) && !new Rectangle((int)(zoomRect.Right - 3), (int)(zoomRect.Bottom - 3), 7, 7).Contains(e.Location))
  611. {
  612. isSelected = true;
  613. }
  614. else
  615. {
  616. isSelected = false;
  617. }
  618. //是否缩放
  619. if (new Rectangle((int)(zoomRect.Right - 3), (int)(zoomRect.Bottom - 3), 7, 7).Contains(e.Location))
  620. {
  621. isResized = true;
  622. }
  623. else
  624. {
  625. isResized = false;
  626. }
  627. }
  628. /// <summary>
  629. /// 缩略图的鼠标拖动事件
  630. /// </summary>
  631. /// <param name="sender"></param>
  632. /// <param name="e"></param>
  633. private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
  634. {
  635. this.pictureBox1.Cursor = Cursors.Default;
  636. if (zoomRect != null)
  637. {
  638. if (zoomRect.Contains(e.Location) && !new Rectangle((int)(zoomRect.Right - 3), (int)(zoomRect.Bottom - 3), 7, 7).Contains(e.Location))
  639. {
  640. this.pictureBox1.Cursor = Cursors.SizeAll;
  641. }
  642. if (new Rectangle((int)(zoomRect.Right - 3), (int)(zoomRect.Bottom - 3), 7, 7).Contains(e.Location))
  643. {
  644. this.pictureBox1.Cursor = Cursors.SizeNWSE;
  645. }
  646. }
  647. if (e.Button != MouseButtons.Left)
  648. return;
  649. //拖拽
  650. if (zoomRect != null && isSelected)
  651. {
  652. isFirst = false;
  653. Point p = e.Location;
  654. int dx = p.X - lastPoint.X;
  655. int dy = p.Y - lastPoint.Y;
  656. lastPoint.X = p.X;
  657. lastPoint.Y = p.Y;
  658. zoomRect.X += dx;
  659. zoomRect.Y += dy;
  660. //控制矩形框不超出缩略图范围
  661. int xc = (this.pictureBox1.Width - this.imageRect.Width) / 2;
  662. int yc = (this.pictureBox1.Height - this.imageRect.Height) / 2;
  663. if (zoomRect.X < xc) zoomRect.X = xc;
  664. if (zoomRect.Y < yc) zoomRect.Y = yc;
  665. if (zoomRect.X + zoomRect.Width > imageRect.Width + xc) zoomRect.X = imageRect.Width - zoomRect.Width + xc;
  666. if (zoomRect.Y + zoomRect.Height > imageRect.Height + yc) zoomRect.Y = imageRect.Height - zoomRect.Height + yc;
  667. this.pictureBox1.Refresh();
  668. //修改滚动条
  669. if (newColtrol != null && newColtrol.isSelect)
  670. {
  671. Point scPoint = newColtrol.workspaceWindow.PanelScrollPosition;
  672. this.newBitmap = newColtrol.workspaceWindow.CompositionSurface.CreateAliasedBitmap();
  673. double scRatioWidth = imageRect.Width / (newBitmap.Width * newColtrol.workspaceWindow.ScaleRatio);
  674. double scRatioHeight = imageRect.Height / (newBitmap.Height * newColtrol.workspaceWindow.ScaleRatio);
  675. double scrollDx = dx / scRatioWidth;
  676. double scrollDy = dy / scRatioHeight;
  677. Point newScPoint = new Point(scPoint.X + Convert.ToInt32(Math.Round(scrollDx)), scPoint.Y + Convert.ToInt32(Math.Round(scrollDy)));
  678. //是否同步
  679. if (this.checkBox1.Checked)
  680. {
  681. for (int i = 0; i < imgCount[this.comboBox1.SelectedIndex]; i++)
  682. {
  683. if (listColControl[i].workspaceWindow.CompositionSurface != null)
  684. {
  685. listColControl[i].workspaceWindow.PanelScrollPosition = newScPoint;
  686. }
  687. }
  688. }
  689. else
  690. {
  691. newColtrol.workspaceWindow.PanelScrollPosition = newScPoint;
  692. }
  693. }
  694. }
  695. //放大缩小
  696. if (zoomRect != null && isResized)
  697. {
  698. isFirst = false;
  699. Point p = e.Location;
  700. int dx = p.X - lastPoint.X;
  701. int dy = p.Y - lastPoint.Y;
  702. lastPoint.X = p.X;
  703. lastPoint.Y = p.Y;
  704. //偏移量取横坐标与纵坐标中绝对值大的
  705. int delta = dx;
  706. if (Math.Abs(dy) > Math.Abs(dx))
  707. delta = dy;
  708. Size size = newColtrol.workspaceWindow.panel.ClientSize;//document尺寸
  709. double ratio = newColtrol.workspaceWindow.ScaleRatio;//缩放比
  710. this.newBitmap = newColtrol.workspaceWindow.CompositionSurface.CreateAliasedBitmap();
  711. double winAspectRatio = (double)size.Width / (double)size.Height;//窗口宽高比
  712. double imgAspectRatio = (double)(imageRect.Width - (zoomRect.X - imageRect.X)) / (double)(imageRect.Height - (zoomRect.Y - imageRect.Y));//最大红框宽高比
  713. //计算临界点红框宽与高
  714. int minWidth = 0;
  715. int minHeight = 0;
  716. if (winAspectRatio < imgAspectRatio)
  717. {
  718. minHeight = imageRect.Height - (zoomRect.Y - imageRect.Y);
  719. minWidth = (int)(minHeight * winAspectRatio);
  720. }
  721. else
  722. {
  723. minWidth = imageRect.Width - (zoomRect.X - imageRect.X);
  724. minHeight = (int)(minWidth / winAspectRatio);
  725. }
  726. //int minWidth = (int)((imageRect.Height - (zoomRect.Y-imageRect.Y)) * winAspectRatio);// 高度与最大高度相等时,缩略图中红框最小宽度
  727. //int minHeight = (int)((imageRect.Width - (zoomRect.X - imageRect.X)) / winAspectRatio);// 宽度与最大宽度相等时,缩略图中红框最小高度
  728. double newScaleRatio = 0;//重新计算缩放率
  729. double criticalRatio = 0; //临界值缩放率
  730. double newScPointX = 0;//计算后新的滚动条横坐标
  731. double newScPointY = 0;//计算后新的滚动条纵坐标
  732. if (winAspectRatio <= imgAspectRatio)
  733. {
  734. criticalRatio = (double)(size.Width) / (double)(this.newBitmap.Width);
  735. }
  736. else
  737. {
  738. criticalRatio = (double)(size.Height) / (double)(this.newBitmap.Height);
  739. }
  740. ////图片缩放后的宽和高都小于document窗口尺寸
  741. //if (size.Width > this.newBitmap.Width * ratio && size.Height > this.newBitmap.Height * ratio)
  742. //{
  743. newColtrol.workspaceWindow.ZoomBasis = ZoomBasis.ScaleFactor;//修改缩放模式
  744. //只修改缩放比,不改变缩略图矩形框尺寸
  745. ratio += (-delta / 100d);
  746. if (ratio < 0.01)
  747. ratio = 0.01;
  748. //是否同步
  749. if (this.checkBox1.Checked)
  750. {
  751. for (int i = 0; i < imgCount[this.comboBox1.SelectedIndex]; i++)
  752. {
  753. if (listColControl[i].workspaceWindow.CompositionSurface != null)
  754. {
  755. if (!listColControl[i].isSelect)
  756. {
  757. continue;
  758. }
  759. else
  760. {
  761. if (winAspectRatio < imgAspectRatio)
  762. {
  763. if (zoomRect.Width > minWidth)
  764. {
  765. zoomRect.Height = minHeight;
  766. }
  767. else
  768. {
  769. zoomRect.Height += dy;
  770. }
  771. //限制最小矩形框
  772. if (zoomRect.Height < 3)
  773. {
  774. zoomRect.Height = 3;
  775. zoomRect.Width = (int)(zoomRect.Height * winAspectRatio);
  776. }
  777. if (zoomRect.Height > 1 && zoomRect.Height < minHeight)
  778. {
  779. zoomRect.Width = (int)(zoomRect.Height * winAspectRatio);
  780. }
  781. if (zoomRect.Height >= minHeight)
  782. {
  783. zoomRect.Height = minHeight;
  784. if (zoomRect.X == imageRect.X && zoomRect.Y == imageRect.Y)
  785. {
  786. zoomRect.Width += dx;
  787. }
  788. else
  789. {
  790. zoomRect.Width = minWidth;
  791. }
  792. if (zoomRect.Width < minWidth)
  793. {
  794. zoomRect.Width = minWidth;
  795. }
  796. else
  797. {
  798. zoomRect.Height = minHeight;
  799. }
  800. }
  801. if (zoomRect.Width > (imageRect.Width - zoomRect.X))
  802. {
  803. zoomRect.Width = imageRect.Width - zoomRect.X;
  804. }
  805. }
  806. else
  807. {
  808. if (zoomRect.Height > minHeight)
  809. {
  810. zoomRect.Width = minWidth;
  811. }
  812. else
  813. {
  814. zoomRect.Width += dx;
  815. }
  816. //限制最小矩形框
  817. if (zoomRect.Width < 3)
  818. {
  819. zoomRect.Width = 3;
  820. zoomRect.Height = (int)(zoomRect.Height / winAspectRatio);
  821. }
  822. if (zoomRect.Width > 1 && zoomRect.Width < imageRect.Width)
  823. {
  824. zoomRect.Height = (int)(zoomRect.Width / winAspectRatio);
  825. }
  826. if (zoomRect.Width >= minWidth)
  827. {
  828. zoomRect.Width = minWidth;
  829. if (zoomRect.X == imageRect.X && zoomRect.Y == imageRect.Y)
  830. {
  831. zoomRect.Height += dy; ;
  832. }
  833. else
  834. {
  835. zoomRect.Height = minHeight;
  836. }
  837. if (zoomRect.Height < minHeight)
  838. {
  839. zoomRect.Height = minHeight;
  840. }
  841. else
  842. {
  843. zoomRect.Width = minWidth;
  844. }
  845. }
  846. if (zoomRect.Height > (imageRect.Height - zoomRect.Y))
  847. {
  848. zoomRect.Height = imageRect.Height - zoomRect.Y;
  849. }
  850. }
  851. double zoomRectWH = (double)zoomRect.Width / (double)zoomRect.Height;
  852. widthRatio = zoomRect.Width / (imageRect.Width * 1d);
  853. if (widthRatio > 1)
  854. widthRatio = 1;
  855. heightRatio = zoomRect.Height / (imageRect.Height * 1d);
  856. if (heightRatio > 1)
  857. heightRatio = 1;
  858. if (zoomRectWH < winAspectRatio)
  859. {
  860. newScaleRatio = Math.Round(size.Height / heightRatio / newBitmap.Height, 10);//重新计算缩放比
  861. if (newScaleRatio < 0.01)
  862. newScaleRatio = 0.01;
  863. }
  864. else
  865. {
  866. newScaleRatio = Math.Round(size.Width / widthRatio / newBitmap.Width, 10);//重新计算缩放比
  867. if (newScaleRatio < 0.01)
  868. newScaleRatio = 0.01;
  869. }
  870. double imgRatio = (double)newBitmap.Width * newScaleRatio / (double)imageRect.Width;//缩放图与缩略图比率
  871. newScPointX = (zoomRect.X - imageRect.X) * imgRatio;//新的X轴滚动条位置
  872. newScPointY = (zoomRect.Y - imageRect.Y) * imgRatio;//新的Y轴滚动条位置
  873. this.pictureBox1.Refresh();
  874. if (newScaleRatio <= criticalRatio)
  875. {
  876. newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(criticalRatio);
  877. newColtrol.workspaceWindow.Refresh();
  878. }
  879. else
  880. {
  881. newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(newScaleRatio);
  882. newColtrol.workspaceWindow.Refresh();
  883. }
  884. newColtrol.workspaceWindow.PanelScrollPosition = new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY));
  885. }
  886. }
  887. }
  888. for (int i = 0; i < imgCount[this.comboBox1.SelectedIndex]; i++)
  889. {
  890. if (listColControl[i].workspaceWindow.CompositionSurface != null)
  891. {
  892. if (listColControl[i].isSelect)
  893. {
  894. continue;
  895. }
  896. else
  897. {
  898. if (listColControl[i].workspaceWindow.ZoomBasis != ZoomBasis.ScaleFactor)
  899. listColControl[i].workspaceWindow.ZoomBasis = ZoomBasis.ScaleFactor;
  900. listColControl[i].workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(newScaleRatio);
  901. listColControl[i].workspaceWindow.Refresh();
  902. }
  903. }
  904. }
  905. }
  906. else
  907. {
  908. if (winAspectRatio < imgAspectRatio)
  909. {
  910. if (zoomRect.Width > minWidth)
  911. {
  912. zoomRect.Height = minHeight;
  913. }
  914. else
  915. {
  916. zoomRect.Height += dy;
  917. }
  918. //限制最小矩形框
  919. if (zoomRect.Height < 3)
  920. {
  921. zoomRect.Height = 3;
  922. zoomRect.Width = (int)(zoomRect.Height * winAspectRatio);
  923. }
  924. if (zoomRect.Height > 1 && zoomRect.Height < minHeight)
  925. {
  926. zoomRect.Width = (int)(zoomRect.Height * winAspectRatio);
  927. }
  928. if (zoomRect.Height >= minHeight)
  929. {
  930. zoomRect.Height = minHeight;
  931. if (zoomRect.X == imageRect.X && zoomRect.Y == imageRect.Y)
  932. {
  933. zoomRect.Width += dx;
  934. }
  935. else
  936. {
  937. zoomRect.Width = minWidth;
  938. }
  939. if (zoomRect.Width < minWidth)
  940. {
  941. zoomRect.Width = minWidth;
  942. }
  943. else
  944. {
  945. zoomRect.Height = minHeight;
  946. }
  947. }
  948. if (zoomRect.Width > (imageRect.Width - zoomRect.X))
  949. {
  950. zoomRect.Width = imageRect.Width - zoomRect.X;
  951. }
  952. }
  953. else
  954. {
  955. if (zoomRect.Height > minHeight)
  956. {
  957. zoomRect.Width = minWidth;
  958. }
  959. else
  960. {
  961. zoomRect.Width += dx;
  962. }
  963. //限制最小矩形框
  964. if (zoomRect.Width < 3)
  965. {
  966. zoomRect.Width = 3;
  967. zoomRect.Height = (int)(zoomRect.Height / winAspectRatio);
  968. }
  969. if (zoomRect.Width > 1 && zoomRect.Width < imageRect.Width)
  970. {
  971. zoomRect.Height = (int)(zoomRect.Width / winAspectRatio);
  972. }
  973. if (zoomRect.Width >= minWidth)
  974. {
  975. zoomRect.Width = minWidth;
  976. if (zoomRect.X == imageRect.X && zoomRect.Y == imageRect.Y)
  977. {
  978. zoomRect.Height += dy;;
  979. }
  980. else
  981. {
  982. zoomRect.Height = minHeight;
  983. }
  984. if (zoomRect.Height < minHeight)
  985. {
  986. zoomRect.Height = minHeight;
  987. }
  988. else
  989. {
  990. zoomRect.Width = minWidth;
  991. }
  992. }
  993. if (zoomRect.Height > (imageRect.Height - zoomRect.Y))
  994. {
  995. zoomRect.Height = imageRect.Height - zoomRect.Y;
  996. }
  997. }
  998. //}
  999. double zoomRectWH = (double)zoomRect.Width / (double)zoomRect.Height;
  1000. widthRatio = zoomRect.Width / (imageRect.Width * 1d);
  1001. if (widthRatio > 1)
  1002. widthRatio = 1;
  1003. heightRatio = zoomRect.Height / (imageRect.Height * 1d);
  1004. if (heightRatio > 1)
  1005. heightRatio = 1;
  1006. if (zoomRectWH < winAspectRatio)
  1007. {
  1008. newScaleRatio = Math.Round(size.Height / heightRatio / newBitmap.Height, 10);//重新计算缩放比
  1009. if (newScaleRatio < 0.01)
  1010. newScaleRatio = 0.01;
  1011. }
  1012. else
  1013. {
  1014. newScaleRatio = Math.Round(size.Width / widthRatio / newBitmap.Width, 10);//重新计算缩放比
  1015. if (newScaleRatio < 0.01)
  1016. newScaleRatio = 0.01;
  1017. }
  1018. double imgRatio = (double)newBitmap.Width * newScaleRatio / (double)imageRect.Width;//缩放图与缩略图比率
  1019. newScPointX = (zoomRect.X - imageRect.X) * imgRatio;//新的X轴滚动条位置
  1020. newScPointY = (zoomRect.Y - imageRect.Y) * imgRatio;//新的Y轴滚动条位置
  1021. this.pictureBox1.Refresh();
  1022. if (newScaleRatio <= criticalRatio)
  1023. {
  1024. newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(criticalRatio);
  1025. newColtrol.workspaceWindow.Refresh();
  1026. }
  1027. else
  1028. {
  1029. newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(newScaleRatio);
  1030. newColtrol.workspaceWindow.Refresh();
  1031. }
  1032. newColtrol.workspaceWindow.PanelScrollPosition = new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY));
  1033. }
  1034. getRatioBetweenPanelWindowAndBitmap(newColtrol);
  1035. this.textBox2.Text = Math.Round(newColtrol.workspaceWindow.ScaleFactor.Ratio * 100) + "%";
  1036. this.textBox2.Refresh();
  1037. //}
  1038. //else
  1039. //{
  1040. // double aspectRatio = size.Width / (size.Height * 1d);//宽高比
  1041. // int maxResizedWidth = imageRect.Right - zoomRect.Right;//正向最大拖动宽度
  1042. // int maxResizedHeigth = imageRect.Bottom - zoomRect.Bottom;//正向最大拖动高度
  1043. // int maxRectWidth = maxResizedWidth + zoomRect.Width;//小矩形可放大到的最大宽度
  1044. // int maxRectHeight = maxResizedHeigth + zoomRect.Height;//小矩形可放大到的最大高度
  1045. // double newScaleRatio = 0;//计算后新的缩放比
  1046. // double newScPointX = 0;//计算后新的滚动条横坐标
  1047. // double newScPointY = 0;//计算后新的滚动条纵坐标
  1048. // double scRatioWidth = 0;
  1049. // double scRatioHeight = 0;
  1050. // //图片缩放后只有宽小于ducument窗口尺寸
  1051. // if (size.Width > this.newBitmap.Width * ratio && size.Height <= this.newBitmap.Height * ratio)
  1052. // {
  1053. // int minHeight = (int)Math.Round(imageRect.Width / aspectRatio);//矩形框可拖动的最小高度
  1054. // double temporaryRatio = 0;
  1055. // zoomRect.Height += delta;
  1056. // if (zoomRect.Height > maxRectHeight)
  1057. // {
  1058. // zoomRect.Height = maxRectHeight;
  1059. // //矩形框的起始点不在缩略图的起始点上时,高度达到默认可变的最大值后,同时修改纵坐标和高度
  1060. // if (maxRectHeight < imageRect.Height)
  1061. // {
  1062. // zoomRect.Y -= delta;
  1063. // if (zoomRect.Y < imageRect.Y)
  1064. // zoomRect.Y = imageRect.Y;
  1065. // zoomRect.Height += delta;
  1066. // if (zoomRect.Height > imageRect.Height)
  1067. // zoomRect.Height = imageRect.Height;
  1068. // this.pictureBox1.Refresh();
  1069. // newScaleRatio = Math.Round(size.Height / heightRatio / this.newBitmap.Height, 2);//重新计算缩放比
  1070. // if (newScaleRatio < 0.01)
  1071. // newScaleRatio = 0.01;
  1072. // //重新计算滚轮所需比例
  1073. // scRatioWidth = imageRect.Width / (newBitmap.Width * newScaleRatio);
  1074. // scRatioHeight = imageRect.Height / (newBitmap.Height * newScaleRatio);
  1075. // //重新计算document的滚动条横坐标与纵坐标
  1076. // newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth;
  1077. // newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight;
  1078. // //是否同步
  1079. // if (this.checkBox1.Checked)
  1080. // {
  1081. // for (int i = 0; i < imgCount[this.comboBox1.SelectedIndex]; i++)
  1082. // {
  1083. // if (listColControl[i].workspaceWindow.CompositionSurface != null)
  1084. // {
  1085. // if (listColControl[i].workspaceWindow.ZoomBasis != ZoomBasis.ScaleFactor)
  1086. // listColControl[i].workspaceWindow.ZoomBasis = ZoomBasis.ScaleFactor;
  1087. // listColControl[i].workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(ratio);
  1088. // listColControl[i].workspaceWindow.PanelScrollPosition = new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY));
  1089. // listColControl[i].workspaceWindow.Refresh();
  1090. // }
  1091. // }
  1092. // }
  1093. // else
  1094. // {
  1095. // if (size.Height == this.newBitmap.Height * ratio)
  1096. // {
  1097. // temporaryRatio = ratio;
  1098. // }
  1099. // if (size.Height >= this.newBitmap.Height * ratio)
  1100. // {
  1101. // newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(temporaryRatio);
  1102. // }
  1103. // else
  1104. // {
  1105. // newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(ratio);
  1106. // }
  1107. // newColtrol.workspaceWindow.PanelScrollPosition = new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY));
  1108. // newColtrol.workspaceWindow.Refresh();
  1109. // }
  1110. // getRatioBetweenPanelWindowAndBitmap(newColtrol);
  1111. // this.textBox2.Text = Math.Round(newColtrol.workspaceWindow.ScaleFactor.Ratio * 100) + "%";
  1112. // this.textBox2.Refresh();
  1113. // return;
  1114. // }
  1115. // //高度达到极限,只改变缩放比
  1116. // this.pictureBox1.Refresh();
  1117. // ratio += (-delta / 100d);
  1118. // if (ratio < 0.01)
  1119. // ratio = 0.01;
  1120. // //是否同步
  1121. // if (this.checkBox1.Checked)
  1122. // {
  1123. // for (int i = 0; i < imgCount[this.comboBox1.SelectedIndex]; i++)
  1124. // {
  1125. // if (listColControl[i].workspaceWindow.CompositionSurface != null)
  1126. // {
  1127. // if (listColControl[i].workspaceWindow.ZoomBasis != ZoomBasis.ScaleFactor)
  1128. // listColControl[i].workspaceWindow.ZoomBasis = ZoomBasis.ScaleFactor;
  1129. // listColControl[i].workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(ratio);
  1130. // listColControl[i].workspaceWindow.Refresh();
  1131. // }
  1132. // }
  1133. // }
  1134. // else
  1135. // {
  1136. // if (size.Height == this.newBitmap.Height * ratio)
  1137. // {
  1138. // temporaryRatio = ratio;
  1139. // }
  1140. // if (size.Height >= this.newBitmap.Height * ratio)
  1141. // {
  1142. // newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(temporaryRatio);
  1143. // }
  1144. // else
  1145. // {
  1146. // newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(ratio);
  1147. // }
  1148. // //newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(ratio);
  1149. // newColtrol.workspaceWindow.Refresh();
  1150. // }
  1151. // return;
  1152. // }
  1153. // if (zoomRect.Height < minHeight)
  1154. // zoomRect.Height = minHeight;
  1155. // this.pictureBox1.Refresh();
  1156. // heightRatio = zoomRect.Height / (imageRect.Height * 1d);
  1157. // if (heightRatio > 1)
  1158. // heightRatio = 1;
  1159. // newScaleRatio = Math.Round(size.Height / heightRatio / this.newBitmap.Height, 2);//重新计算缩放比
  1160. // }
  1161. // //图片缩放后只有高小于ducument窗口尺寸
  1162. // if (size.Width <= this.newBitmap.Width * ratio && size.Height >= this.newBitmap.Height * ratio)
  1163. // {
  1164. // int minWidth = (int)Math.Round(zoomRect.Height * aspectRatio);//矩形框可拖动的最小宽度
  1165. // double temporaryRatio = 0;
  1166. // zoomRect.Width += delta;
  1167. // if (zoomRect.Width > maxRectWidth)
  1168. // {
  1169. // zoomRect.Width = maxRectWidth;
  1170. // //矩形框的起始点不在缩略图的起始点上时,宽度达到默认可变的最大值后,同时修改横坐标和宽度
  1171. // if (maxRectWidth < imageRect.Width)
  1172. // {
  1173. // zoomRect.X -= delta;
  1174. // if (zoomRect.X < imageRect.X)
  1175. // zoomRect.X = imageRect.X;
  1176. // zoomRect.Width += delta;
  1177. // if (zoomRect.Width > imageRect.Width)
  1178. // zoomRect.Width = imageRect.Width;
  1179. // this.pictureBox1.Refresh();
  1180. // newScaleRatio = Math.Round(size.Width / widthRatio / this.newBitmap.Width, 2);//重新计算缩放比
  1181. // if (newScaleRatio < 0.01)
  1182. // newScaleRatio = 0.01;
  1183. // //重新计算滚轮所需比例
  1184. // scRatioWidth = imageRect.Width / (newBitmap.Width * newScaleRatio);
  1185. // scRatioHeight = imageRect.Height / (newBitmap.Height * newScaleRatio);
  1186. // //重新计算document的滚动条横坐标与纵坐标
  1187. // newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth;
  1188. // newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight;
  1189. // //是否同步
  1190. // if (this.checkBox1.Checked)
  1191. // {
  1192. // for (int i = 0; i < imgCount[this.comboBox1.SelectedIndex]; i++)
  1193. // {
  1194. // if (listColControl[i].workspaceWindow.CompositionSurface != null)
  1195. // {
  1196. // if (listColControl[i].workspaceWindow.ZoomBasis != ZoomBasis.ScaleFactor)
  1197. // listColControl[i].workspaceWindow.ZoomBasis = ZoomBasis.ScaleFactor;
  1198. // listColControl[i].workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(newScaleRatio);
  1199. // listColControl[i].workspaceWindow.PanelScrollPosition = new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY));
  1200. // listColControl[i].workspaceWindow.Refresh();
  1201. // }
  1202. // }
  1203. // }
  1204. // else
  1205. // {
  1206. // if (size.Width == this.newBitmap.Width * ratio)
  1207. // {
  1208. // temporaryRatio = ratio;
  1209. // }
  1210. // if (size.Width >= this.newBitmap.Width * ratio)
  1211. // {
  1212. // newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(temporaryRatio);
  1213. // }
  1214. // else
  1215. // {
  1216. // newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(ratio);
  1217. // }
  1218. // //newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(newScaleRatio);
  1219. // newColtrol.workspaceWindow.PanelScrollPosition = new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY));
  1220. // newColtrol.workspaceWindow.Refresh();
  1221. // }
  1222. // getRatioBetweenPanelWindowAndBitmap(newColtrol);
  1223. // this.textBox2.Text = Math.Round(newColtrol.workspaceWindow.ScaleFactor.Ratio * 100) + "%";
  1224. // this.textBox2.Refresh();
  1225. // return;
  1226. // }
  1227. // //宽度达到极限,改变缩放比
  1228. // this.pictureBox1.Refresh();
  1229. // ratio += (-delta / 100d);
  1230. // if (ratio < 0.01)
  1231. // ratio = 0.01;
  1232. // //是否同步
  1233. // if (this.checkBox1.Checked)
  1234. // {
  1235. // for (int i = 0; i < imgCount[this.comboBox1.SelectedIndex]; i++)
  1236. // {
  1237. // if (listColControl[i].workspaceWindow.CompositionSurface != null)
  1238. // {
  1239. // if (listColControl[i].workspaceWindow.ZoomBasis != ZoomBasis.ScaleFactor)
  1240. // listColControl[i].workspaceWindow.ZoomBasis = ZoomBasis.ScaleFactor;
  1241. // listColControl[i].workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(ratio);
  1242. // listColControl[i].workspaceWindow.Refresh();
  1243. // }
  1244. // }
  1245. // }
  1246. // else
  1247. // {
  1248. // if (size.Width == this.newBitmap.Width * ratio)
  1249. // {
  1250. // temporaryRatio = ratio;
  1251. // }
  1252. // if (size.Width >= this.newBitmap.Width * ratio)
  1253. // {
  1254. // newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(temporaryRatio);
  1255. // }
  1256. // else
  1257. // {
  1258. // newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(ratio);
  1259. // }
  1260. // //newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(ratio);
  1261. // newColtrol.workspaceWindow.Refresh();
  1262. // }
  1263. // getRatioBetweenPanelWindowAndBitmap(newColtrol);
  1264. // this.textBox2.Text = Math.Round(newColtrol.workspaceWindow.ScaleFactor.Ratio * 100) + "%";
  1265. // this.textBox2.Refresh();
  1266. // return;
  1267. // }
  1268. // if (zoomRect.Width < minWidth)
  1269. // zoomRect.Width = minWidth;
  1270. // this.pictureBox1.Refresh();
  1271. // widthRatio = zoomRect.Width / (imageRect.Width * 1d);
  1272. // if (widthRatio > 1)
  1273. // widthRatio = 1;
  1274. // newScaleRatio = Math.Round(size.Width / widthRatio / this.newBitmap.Width, 2);//重新计算缩放比
  1275. // }
  1276. // //图片缩放后的宽和高都不小于document窗体尺寸
  1277. // if (size.Width <= this.newBitmap.Width * ratio && size.Height <= this.newBitmap.Height * ratio)
  1278. // {
  1279. // if (maxResizedWidth < maxResizedHeigth)
  1280. // {
  1281. // zoomRect.Width += delta;
  1282. // if (zoomRect.Width > maxRectWidth)
  1283. // {
  1284. // zoomRect.Width = maxRectWidth;
  1285. // //矩形框的宽度与缩略图宽度相同时才可改变高度并调整缩放比
  1286. // if (zoomRect.Width >= imageRect.Width)
  1287. // {
  1288. // zoomRect.Height += delta;
  1289. // this.pictureBox1.Refresh();
  1290. // heightRatio = zoomRect.Height / (imageRect.Height * 1d);
  1291. // if (heightRatio > 1)
  1292. // heightRatio = 1;
  1293. // newScaleRatio = Math.Round(size.Height / heightRatio / newBitmap.Height, 2);//重新计算缩放比
  1294. // if (newScaleRatio < 0.01)
  1295. // newScaleRatio = 0.01;
  1296. // //重新计算滚轮所需比例
  1297. // scRatioWidth = imageRect.Width / (newBitmap.Width * newScaleRatio);
  1298. // scRatioHeight = imageRect.Height / (newBitmap.Height * newScaleRatio);
  1299. // //重新计算document的滚动条横坐标与纵坐标
  1300. // newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth;
  1301. // newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight;
  1302. // //是否同步
  1303. // if (this.checkBox1.Checked)
  1304. // {
  1305. // for (int i = 0; i < imgCount[this.comboBox1.SelectedIndex]; i++)
  1306. // {
  1307. // if (listColControl[i].workspaceWindow.CompositionSurface != null)
  1308. // {
  1309. // if (listColControl[i].workspaceWindow.ZoomBasis != ZoomBasis.ScaleFactor)
  1310. // listColControl[i].workspaceWindow.ZoomBasis = ZoomBasis.ScaleFactor;
  1311. // listColControl[i].workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(newScaleRatio);
  1312. // listColControl[i].workspaceWindow.PanelScrollPosition = new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY));
  1313. // listColControl[i].workspaceWindow.Refresh();
  1314. // }
  1315. // }
  1316. // }
  1317. // else
  1318. // {
  1319. // newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(newScaleRatio);
  1320. // newColtrol.workspaceWindow.PanelScrollPosition = new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY));
  1321. // newColtrol.workspaceWindow.Refresh();
  1322. // }
  1323. // getRatioBetweenPanelWindowAndBitmap(newColtrol);
  1324. // this.textBox2.Text = Math.Round(newColtrol.workspaceWindow.ScaleFactor.Ratio * 100) + "%";
  1325. // this.textBox2.Refresh();
  1326. // return;
  1327. // }
  1328. // }
  1329. // if (zoomRect.Width < minRectWidth)
  1330. // zoomRect.Width = minRectWidth;
  1331. // zoomRect.Height = (int)Math.Round(zoomRect.Width / aspectRatio);
  1332. // }
  1333. // else
  1334. // {
  1335. // zoomRect.Height += delta;
  1336. // if (zoomRect.Height > maxRectHeight)
  1337. // {
  1338. // zoomRect.Height = maxRectHeight;
  1339. // //矩形框的高度与缩略图高度相同时才可改变宽度并调整缩放比
  1340. // if (zoomRect.Height >= imageRect.Height)
  1341. // {
  1342. // zoomRect.Width += delta;
  1343. // this.pictureBox1.Refresh();
  1344. // widthRatio = zoomRect.Width / (imageRect.Width * 1d);
  1345. // if (widthRatio > 1)
  1346. // widthRatio = 1;
  1347. // newScaleRatio = Math.Round(size.Width / widthRatio / newBitmap.Width, 2);//重新计算缩放比
  1348. // if (newScaleRatio < 0.01)
  1349. // newScaleRatio = 0.01;
  1350. // //重新计算滚轮所需比例
  1351. // scRatioWidth = imageRect.Width / (newBitmap.Width * newScaleRatio);
  1352. // scRatioHeight = imageRect.Height / (newBitmap.Height * newScaleRatio);
  1353. // //重新计算document的滚动条横坐标与纵坐标
  1354. //newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth;
  1355. // newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight;
  1356. // //是否同步
  1357. // if (this.checkBox1.Checked)
  1358. // {
  1359. // for (int i = 0; i < imgCount[this.comboBox1.SelectedIndex]; i++)
  1360. // {
  1361. // if (listColControl[i].workspaceWindow.CompositionSurface != null)
  1362. // {
  1363. // if (listColControl[i].workspaceWindow.ZoomBasis != ZoomBasis.ScaleFactor)
  1364. // listColControl[i].workspaceWindow.ZoomBasis = ZoomBasis.ScaleFactor;
  1365. // listColControl[i].workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(newScaleRatio);
  1366. // listColControl[i].workspaceWindow.PanelScrollPosition = new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY));
  1367. // listColControl[i].workspaceWindow.Refresh();
  1368. // }
  1369. // }
  1370. // }
  1371. // else
  1372. // {
  1373. // newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(newScaleRatio);
  1374. // newColtrol.workspaceWindow.PanelScrollPosition = new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY));
  1375. // newColtrol.workspaceWindow.Refresh();
  1376. // }
  1377. // getRatioBetweenPanelWindowAndBitmap(newColtrol);
  1378. // this.textBox2.Text = Math.Round(newColtrol.workspaceWindow.ScaleFactor.Ratio * 100) + "%";
  1379. // this.textBox2.Refresh();
  1380. // return;
  1381. // }
  1382. // }
  1383. // if (zoomRect.Height < minRectHeight)
  1384. // zoomRect.Height = minRectHeight;
  1385. // zoomRect.Width = (int)Math.Round(zoomRect.Height * aspectRatio);
  1386. // }
  1387. // this.pictureBox1.Refresh();
  1388. // //重新计算比例
  1389. // widthRatio = zoomRect.Width / (imageRect.Width * 1d);
  1390. // if (widthRatio > 1)
  1391. // widthRatio = 1;
  1392. // heightRatio = zoomRect.Height / (imageRect.Height * 1d);
  1393. // if (heightRatio > 1)
  1394. // heightRatio = 1;
  1395. // //计算document的缩放比,宽和高的计算结果会有细微差异
  1396. // double scaleW = Math.Round(size.Width / widthRatio / newBitmap.Width, 2);
  1397. // double scaleH = Math.Round(size.Height / heightRatio / newBitmap.Height, 2);
  1398. // //取大的值作为新的缩放比?不确定
  1399. // if (scaleW >= scaleH)
  1400. // newScaleRatio = scaleW;
  1401. // else
  1402. // newScaleRatio = scaleH;
  1403. // }
  1404. // //重新计算滚轮所需比例
  1405. // scRatioWidth = imageRect.Width / (newBitmap.Width * newScaleRatio);
  1406. // scRatioHeight = imageRect.Height / (newBitmap.Height * newScaleRatio);
  1407. // //重新计算document的滚动条横坐标与纵坐标
  1408. // newScPointX = (zoomRect.X - imageRect.X) / scRatioWidth;
  1409. // newScPointY = (zoomRect.Y - imageRect.Y) / scRatioHeight;
  1410. // //是否同步
  1411. // if (this.checkBox1.Checked)
  1412. // {
  1413. // for (int i = 0; i < imgCount[this.comboBox1.SelectedIndex]; i++)
  1414. // {
  1415. // if (listColControl[i].workspaceWindow.CompositionSurface != null)
  1416. // {
  1417. // if (listColControl[i].workspaceWindow.ZoomBasis != ZoomBasis.ScaleFactor)
  1418. // listColControl[i].workspaceWindow.ZoomBasis = ZoomBasis.ScaleFactor;
  1419. // listColControl[i].workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(newScaleRatio);
  1420. // listColControl[i].workspaceWindow.PanelScrollPosition = new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY));
  1421. // listColControl[i].workspaceWindow.Refresh();
  1422. // }
  1423. // }
  1424. // }
  1425. // else
  1426. // {
  1427. // newColtrol.workspaceWindow.ScaleFactor = ScaleFactor.FromDouble(newScaleRatio);
  1428. // newColtrol.workspaceWindow.PanelScrollPosition = new Point((int)Math.Round(newScPointX), (int)Math.Round(newScPointY));
  1429. // newColtrol.workspaceWindow.Refresh();
  1430. // }
  1431. //}
  1432. getRatioBetweenPanelWindowAndBitmap(newColtrol);
  1433. this.textBox2.Text = Math.Round(newColtrol.workspaceWindow.ScaleFactor.Ratio * 100) + "%";
  1434. this.textBox2.Refresh();
  1435. }
  1436. }
  1437. private void panel2_Click(object sender, EventArgs e)
  1438. {
  1439. this.colorsForm.UserPrimaryColor = ColorBgra.FromColor(this.panel2.BackColor);
  1440. this.colorsForm.setSaveBtn_Click(new System.EventHandler(this.panel2Changed));
  1441. this.colorsForm.ShowDialog();
  1442. }
  1443. /// <summary>
  1444. /// 合并并创建图片
  1445. /// </summary>
  1446. /// <param name="sender"></param>
  1447. /// <param name="e"></param>
  1448. private void button1_Click(object sender, EventArgs e)
  1449. {
  1450. Bitmap[] bitmaps = new Bitmap[imgCount[this.comboBox1.SelectedIndex]];
  1451. int[] oneHeight = new int[imgCount[this.comboBox1.SelectedIndex]];
  1452. for (int i = 0; i < imgCount[this.comboBox1.SelectedIndex]; i++)
  1453. {
  1454. if (this.listColControl[i].workspaceWindow.CompositionSurface != null)
  1455. {
  1456. Size size = this.listColControl[i].workspaceWindow.panel.ClientSize;
  1457. Bitmap compareBit = this.listColControl[i].workspaceWindow.CompositionSurface.CreateAliasedBitmap();
  1458. double compareRatio = this.listColControl[i].workspaceWindow.ScaleRatio;
  1459. if (compareBit.Width * compareRatio >= size.Width && compareBit.Height * compareRatio >= size.Height)
  1460. {
  1461. //bitmaps[i] = this.listColControl[i].workspaceWindow.GetClientRangePic();
  1462. //Rectangle rc = this.listColControl[i].workspaceWindow.panel.ClientRectangle;
  1463. //int width = (int)(this.listColControl[i].workspaceWindow.CompositionSurface.Width * compareRatio);
  1464. //int height = (int)(this.listColControl[i].workspaceWindow.CompositionSurface.Height * compareRatio);
  1465. //int x = (rc.Width < width) ? this.listColControl[i].workspaceWindow.panel.AutoScrollPosition.X : (rc.Width - width) / 2;
  1466. //int y = (rc.Height < height) ? this.listColControl[i].workspaceWindow.panel.AutoScrollPosition.Y : (rc.Height - height) / 2;
  1467. //DocumentView documentView = new DocumentView();
  1468. //if (this.listColControl[i].workspaceWindow.CompositionSurface.CreateAliasedBitmap() != null)
  1469. //{
  1470. // using (Surface doubleBuffer = documentView.GetDoubleBuffer(new Size((rc.Width < width) ? rc.Width : width, (rc.Height < height) ? rc.Height : height)))
  1471. // {
  1472. // using (RenderArgs renderArgs = new RenderArgs(doubleBuffer))
  1473. // {
  1474. // documentView.DrawArea(renderArgs, new Point((rc.Width < width) ? -x : 0, (rc.Height < height) ? -y : 0));
  1475. // bitmaps[i] = doubleBuffer.CreateAliasedBitmap();
  1476. // }
  1477. // }
  1478. //}
  1479. //bitmaps[i] = this.compositionSurface.CreateAliasedBitmap();
  1480. if (compareRatio < 1)
  1481. {
  1482. int x = Math.Abs((int)(this.listColControl[i].workspaceWindow.panel.AutoScrollPosition.X / compareRatio));
  1483. int y = Math.Abs((int)(this.listColControl[i].workspaceWindow.panel.AutoScrollPosition.Y / compareRatio));
  1484. int width = (int)(size.Width / compareRatio);
  1485. int height = (int)(size.Height / compareRatio);
  1486. bitmaps[i] = CaptureImage(compareBit, x, y, width, height);
  1487. }
  1488. else
  1489. {
  1490. Bitmap bmp = new Bitmap(size.Width, size.Height);
  1491. this.listColControl[i].workspaceWindow.panel.DrawToBitmap(bmp, this.listColControl[i].workspaceWindow.panel.ClientRectangle);
  1492. bitmaps[i] = bmp;
  1493. }
  1494. }
  1495. else
  1496. {
  1497. //bitmaps[i] = GetScaleBitmap(compareBit, compareRatio);//获得缩放后的原图
  1498. ////截取显示区域对应的图片
  1499. //int newWidth = 0;
  1500. //if (bitmaps[i].Width <= size.Width)
  1501. // newWidth = bitmaps[i].Width;
  1502. //else
  1503. // newWidth = size.Width;
  1504. //int newHeight = 0;
  1505. //if (bitmaps[i].Height <= size.Height)
  1506. // newHeight = bitmaps[i].Height;
  1507. //else
  1508. // newHeight = size.Height;
  1509. //Point scPoint = this.listColControl[i].workspaceWindow.PanelScrollPosition;//滚轮位置
  1510. //Bitmap newCompareBit = new Bitmap(newWidth, newHeight);
  1511. //Graphics g = Graphics.FromImage(newCompareBit);
  1512. //g.Clear(Color.Black);
  1513. ////设置画布的描绘质量
  1514. //g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
  1515. //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
  1516. //g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
  1517. //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);
  1518. //g.Dispose();
  1519. bitmaps[i] = compareBit;
  1520. }
  1521. oneHeight[i] = bitmaps[i].Height;
  1522. }
  1523. }
  1524. int onePicHeight = oneHeight.Max();
  1525. Bitmap joinedBitmap = JoinBitmap(bitmaps, onePicHeight);
  1526. if (joinedBitmap != null)
  1527. {
  1528. OpenFileImpl(joinedBitmap);
  1529. this.Close();
  1530. }
  1531. else
  1532. {
  1533. MessageBox.Show(PdnResources.GetString("Menu.Pleaseselectapicture.text"));
  1534. }
  1535. }
  1536. /// <summary>
  1537. /// 创建新图片
  1538. /// </summary>
  1539. /// <param name="mat"></param>
  1540. private void OpenFileImpl(Bitmap bitmap)
  1541. {
  1542. if (bitmap != null)
  1543. {
  1544. DocumentWorkspace dw = this.appWorkspace.AddNewDocumentWorkspace();
  1545. dw.Document = Document.FromImage(bitmap);
  1546. dw.xmlSaveModel = Startup.instance.ruleDB;
  1547. dw.InitRulerInfo();
  1548. stepLength = "00" + Startup.instance.step_length;
  1549. // TODO ZYH 这里的图像名称,需要走系统的配置
  1550. dw.fileText = this.Text + "-" + stepLength;
  1551. this.appWorkspace.ActiveDocumentWorkspace = dw;
  1552. //this.appWorkspace.ActiveDocumentWorkspace.PanelBottom.documentStrip.ShowPictures = false;
  1553. this.appWorkspace.ActiveDocumentWorkspace.Refresh();
  1554. Startup.instance.step_length += 1;
  1555. }
  1556. }
  1557. /// <summary>
  1558. /// 拼接图片
  1559. /// </summary>
  1560. /// <param name="bitmaps"></param>
  1561. /// <param name="onePicWidth"></param>
  1562. /// <param name="onePicHeight"></param>
  1563. /// <returns></returns>
  1564. private Bitmap JoinBitmap(Bitmap[] bitmaps, int onePicHeight)
  1565. {
  1566. if (bitmaps == null || onePicHeight <= 0)
  1567. return null;
  1568. Bitmap joinBitmap;
  1569. int[] everyRowWidth = new int[] { 0, 0, 0, 0 };
  1570. for (int i = 0; i < bitmaps.Count(); i++)
  1571. {
  1572. if (bitmaps[i] != null)
  1573. {
  1574. if (bitmaps[i].Height < onePicHeight)
  1575. {
  1576. bitmaps[i] = GetScaleBitmap(bitmaps[i], (double)onePicHeight / (double)bitmaps[i].Height);
  1577. }
  1578. }
  1579. }
  1580. switch (imgCount[this.comboBox1.SelectedIndex])
  1581. {
  1582. case 2:
  1583. int[] rowOneWidth2 = new int[] { bitmaps[0] == null ? 0 : bitmaps[0].Width };
  1584. int[] rowTwoWidth2 = new int[] { bitmaps[1] == null ? 0 : bitmaps[1].Width };
  1585. //每列的最大宽度集合
  1586. int[] maxLstWidth2 = new int[] { rowOneWidth2.Max(), rowTwoWidth2.Max() };
  1587. //获取最大宽度列,用来代替没有图片的列
  1588. int maxWidth2 = maxLstWidth2.Max();
  1589. if (rowOneWidth2.Max() == 0)
  1590. {
  1591. everyRowWidth[0] = maxWidth2;
  1592. }
  1593. else
  1594. {
  1595. everyRowWidth[0] = rowOneWidth2.Max();
  1596. }
  1597. if (rowTwoWidth2.Max() == 0)
  1598. {
  1599. everyRowWidth[1] = maxWidth2;
  1600. }
  1601. else
  1602. {
  1603. everyRowWidth[1] = rowTwoWidth2.Max();
  1604. }
  1605. imgWidth = everyRowWidth.Sum() + int.Parse(this.textBox1.Text);
  1606. imgHeight = onePicHeight;
  1607. break;
  1608. case 3:
  1609. int[] rowOneWidth3 = new int[] { bitmaps[0] == null ? 0 : bitmaps[0].Width };
  1610. int[] rowTwoWidth3 = new int[] { bitmaps[1] == null ? 0 : bitmaps[1].Width };
  1611. int[] rowThreeWidth3 = new int[] { bitmaps[2] == null ? 0 : bitmaps[2].Width };
  1612. //每列的最大宽度集合
  1613. int[] maxLstWidth3 = new int[] { rowOneWidth3.Max(), rowTwoWidth3.Max(), rowThreeWidth3.Max() };
  1614. //获取最大宽度列,用来代替没有图片的列
  1615. int maxWidth3 = maxLstWidth3.Max();
  1616. int[] Width3 = new int[3];
  1617. if (rowOneWidth3.Max() == 0)
  1618. {
  1619. everyRowWidth[0] = maxWidth3;
  1620. }
  1621. else
  1622. {
  1623. everyRowWidth[0] = rowOneWidth3.Max();
  1624. }
  1625. if (rowTwoWidth3.Max() == 0)
  1626. {
  1627. everyRowWidth[1] = maxWidth3;
  1628. }
  1629. else
  1630. {
  1631. everyRowWidth[1] = rowTwoWidth3.Max();
  1632. }
  1633. if (rowThreeWidth3.Max() == 0)
  1634. {
  1635. everyRowWidth[2] = maxWidth3;
  1636. }
  1637. else
  1638. {
  1639. everyRowWidth[2] = rowThreeWidth3.Max();
  1640. }
  1641. imgWidth = everyRowWidth.Sum() + int.Parse(this.textBox1.Text) * 2;
  1642. imgHeight = onePicHeight;
  1643. break;
  1644. case 4:
  1645. int[] rowOneWidth4 = new int[] { bitmaps[0] == null ? 0 : bitmaps[0].Width, bitmaps[2] == null ? 0 : bitmaps[2].Width };
  1646. int[] rowTwoWidth4 = new int[] { bitmaps[1] == null ? 0 : bitmaps[1].Width, bitmaps[3] == null ? 0 : bitmaps[3].Width };
  1647. //每列的最大宽度集合
  1648. int[] maxLstWidth4 = new int[] { rowOneWidth4.Max(), rowTwoWidth4.Max() };
  1649. //获取最大宽度列,用来代替没有图片的列
  1650. int maxWidth4 = maxLstWidth4.Max();
  1651. if (rowOneWidth4.Max() == 0)
  1652. {
  1653. everyRowWidth[0] = maxWidth4;
  1654. }
  1655. else
  1656. {
  1657. everyRowWidth[0] = rowOneWidth4.Max();
  1658. }
  1659. if (rowTwoWidth4.Max() == 0)
  1660. {
  1661. everyRowWidth[1] = maxWidth4;
  1662. }
  1663. else
  1664. {
  1665. everyRowWidth[1] = rowTwoWidth4.Max();
  1666. }
  1667. imgWidth = everyRowWidth.Sum() + int.Parse(this.textBox1.Text);
  1668. imgHeight = onePicHeight * 2 + int.Parse(this.textBox1.Text);
  1669. break;
  1670. case 6:
  1671. int[] rowOneWidth6 = new int[] { bitmaps[0] == null ? 0 : bitmaps[0].Width, bitmaps[3] == null ? 0 : bitmaps[3].Width };
  1672. int[] rowTwoWidth6 = new int[] { bitmaps[1] == null ? 0 : bitmaps[1].Width, bitmaps[4] == null ? 0 : bitmaps[4].Width };
  1673. int[] rowThreeWidth6 = new int[] { bitmaps[2] == null ? 0 : bitmaps[2].Width, bitmaps[5] == null ? 0 : bitmaps[5].Width };
  1674. //每列的最大宽度集合
  1675. int[] maxLstWidth6 = new int[] { rowOneWidth6.Max(), rowTwoWidth6.Max(), rowThreeWidth6.Max() };
  1676. //获取最大宽度列,用来代替没有图片的列
  1677. int maxWidth6 = maxLstWidth6.Max();
  1678. int[] Width6 = new int[3];
  1679. if (rowOneWidth6.Max() == 0)
  1680. {
  1681. everyRowWidth[0] = maxWidth6;
  1682. }
  1683. else
  1684. {
  1685. everyRowWidth[0] = rowOneWidth6.Max();
  1686. }
  1687. if (rowTwoWidth6.Max() == 0)
  1688. {
  1689. everyRowWidth[1] = maxWidth6;
  1690. }
  1691. else
  1692. {
  1693. everyRowWidth[1] = rowTwoWidth6.Max();
  1694. }
  1695. if (rowThreeWidth6.Max() == 0)
  1696. {
  1697. everyRowWidth[2] = maxWidth6;
  1698. }
  1699. else
  1700. {
  1701. everyRowWidth[2] = rowThreeWidth6.Max();
  1702. }
  1703. imgWidth = everyRowWidth.Sum() + int.Parse(this.textBox1.Text) * 2;
  1704. imgHeight = onePicHeight * 2 + int.Parse(this.textBox1.Text);
  1705. break;
  1706. case 8:
  1707. int[] rowOneWidth8 = new int[] { bitmaps[0] == null ? 0 : bitmaps[0].Width, bitmaps[4] == null ? 0 : bitmaps[4].Width };
  1708. int[] rowTwoWidth8 = new int[] { bitmaps[1] == null ? 0 : bitmaps[1].Width, bitmaps[5] == null ? 0 : bitmaps[5].Width };
  1709. int[] rowThreeWidth8 = new int[] { bitmaps[2] == null ? 0 : bitmaps[2].Width, bitmaps[6] == null ? 0 : bitmaps[6].Width };
  1710. int[] rowFourWidth8 = new int[] { bitmaps[3] == null ? 0 : bitmaps[3].Width, bitmaps[7] == null ? 0 : bitmaps[7].Width };
  1711. //每列的最大宽度集合
  1712. int[] maxLstWidth8 = new int[] { rowOneWidth8.Max(), rowTwoWidth8.Max(), rowThreeWidth8.Max(), rowFourWidth8.Max() };
  1713. //获取最大宽度列,用来代替没有图片的列
  1714. int maxWidth8 = maxLstWidth8.Max();
  1715. int[] Width8 = new int[3];
  1716. if (rowOneWidth8.Max() == 0)
  1717. {
  1718. everyRowWidth[0] = maxWidth8;
  1719. }
  1720. else
  1721. {
  1722. everyRowWidth[0] = rowOneWidth8.Max();
  1723. }
  1724. if (rowTwoWidth8.Max() == 0)
  1725. {
  1726. everyRowWidth[1] = maxWidth8;
  1727. }
  1728. else
  1729. {
  1730. everyRowWidth[1] = rowTwoWidth8.Max();
  1731. }
  1732. if (rowThreeWidth8.Max() == 0)
  1733. {
  1734. everyRowWidth[2] = maxWidth8;
  1735. }
  1736. else
  1737. {
  1738. everyRowWidth[2] = rowThreeWidth8.Max();
  1739. }
  1740. if (rowFourWidth8.Max() == 0)
  1741. {
  1742. everyRowWidth[3] = maxWidth8;
  1743. }
  1744. else
  1745. {
  1746. everyRowWidth[3] = rowFourWidth8.Max();
  1747. }
  1748. imgWidth = everyRowWidth.Sum() + int.Parse(this.textBox1.Text) * 3;
  1749. imgHeight = onePicHeight * 2 + int.Parse(this.textBox1.Text);
  1750. break;
  1751. case 9:
  1752. 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 };
  1753. 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 };
  1754. 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 };
  1755. //每列的最大宽度集合
  1756. int[] maxLstWidth9 = new int[] { rowOneWidth9.Max(), rowTwoWidth9.Max(), rowThreeWidth9.Max() };
  1757. //获取最大宽度列,用来代替没有图片的列
  1758. int maxWidth9 = maxLstWidth9.Max();
  1759. int[] Width9 = new int[3];
  1760. if (rowOneWidth9.Max() == 0)
  1761. {
  1762. everyRowWidth[0] = maxWidth9;
  1763. }
  1764. else
  1765. {
  1766. everyRowWidth[0] = rowOneWidth9.Max();
  1767. }
  1768. if (rowTwoWidth9.Max() == 0)
  1769. {
  1770. everyRowWidth[1] = maxWidth9;
  1771. }
  1772. else
  1773. {
  1774. everyRowWidth[1] = rowTwoWidth9.Max();
  1775. }
  1776. if (rowThreeWidth9.Max() == 0)
  1777. {
  1778. everyRowWidth[2] = maxWidth9;
  1779. }
  1780. else
  1781. {
  1782. everyRowWidth[2] = rowThreeWidth9.Max();
  1783. }
  1784. imgWidth = everyRowWidth.Sum() + int.Parse(this.textBox1.Text) * 2;
  1785. imgHeight = onePicHeight * 3 + int.Parse(this.textBox1.Text) * 2;
  1786. break;
  1787. }
  1788. if (imgWidth > 0 && imgHeight > 0)
  1789. {
  1790. joinBitmap = new Bitmap(imgWidth, imgHeight);
  1791. joinBitmap = JoinAllBitmap(joinBitmap, bitmaps, everyRowWidth, onePicHeight);
  1792. return joinBitmap;
  1793. }
  1794. else
  1795. {
  1796. return null;
  1797. }
  1798. }
  1799. /// <summary>
  1800. /// 获取按比例缩放的图片
  1801. /// </summary>
  1802. /// <param name="bit"></param>
  1803. /// <param name="ratio"></param>
  1804. /// <returns></returns>
  1805. private Bitmap GetScaleBitmap(Bitmap bit, double ratio)
  1806. {
  1807. Bitmap destBitmap = new Bitmap(Convert.ToInt32(bit.Width * ratio), Convert.ToInt32(bit.Height * ratio));
  1808. Graphics g = Graphics.FromImage(destBitmap);
  1809. g.Clear(this.panel2.BackColor);
  1810. //设置画布的描绘质量
  1811. g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
  1812. g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
  1813. g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
  1814. g.DrawImage(bit, new Rectangle(0, 0, destBitmap.Width, destBitmap.Height), 0, 0, bit.Width, bit.Height, GraphicsUnit.Pixel);
  1815. g.Dispose();
  1816. return destBitmap;
  1817. }
  1818. /// <summary>
  1819. /// 把小图拼到一起
  1820. /// </summary>
  1821. /// <param name="bmp"></param>
  1822. /// <param name="bitmaps"></param>
  1823. /// <param name="onePicWidth"></param>
  1824. /// <param name="onePicHeight"></param>
  1825. /// <returns></returns>
  1826. private Bitmap JoinAllBitmap(Bitmap bmp, Bitmap[] bitmaps, int[] everyRowWidth, int onePicHeight)
  1827. {
  1828. int imgCount = bitmaps.Count();
  1829. Graphics graph = Graphics.FromImage(bmp);
  1830. graph.FillRectangle(new SolidBrush(this.panel2.BackColor), 0, 0, imgWidth, imgHeight);
  1831. graph.DrawImage(bmp, imgWidth, imgHeight);
  1832. switch (imgCount)
  1833. {
  1834. case 2:
  1835. if (bitmaps[0] != null)
  1836. {
  1837. graph.DrawImage(bitmaps[0], 0, 0);
  1838. }
  1839. if (bitmaps[1] != null)
  1840. {
  1841. graph.DrawImage(bitmaps[1], everyRowWidth[0] + int.Parse(this.textBox1.Text), 0);
  1842. }
  1843. break;
  1844. case 3:
  1845. if (bitmaps[0] != null)
  1846. {
  1847. graph.DrawImage(bitmaps[0], 0, 0);
  1848. }
  1849. if (bitmaps[1] != null)
  1850. {
  1851. graph.DrawImage(bitmaps[1], everyRowWidth[0] + int.Parse(this.textBox1.Text), 0);
  1852. }
  1853. if (bitmaps[2] != null)
  1854. {
  1855. graph.DrawImage(bitmaps[2], everyRowWidth[0] + everyRowWidth[1] + int.Parse(this.textBox1.Text) * 2, 0);
  1856. }
  1857. break;
  1858. case 4:
  1859. if (bitmaps[0] != null)
  1860. {
  1861. graph.DrawImage(bitmaps[0], 0, 0);
  1862. }
  1863. if (bitmaps[1] != null)
  1864. {
  1865. graph.DrawImage(bitmaps[1], everyRowWidth[0] + int.Parse(this.textBox1.Text), 0);
  1866. }
  1867. if (bitmaps[2] != null)
  1868. {
  1869. graph.DrawImage(bitmaps[2], 0, onePicHeight + int.Parse(this.textBox1.Text));
  1870. }
  1871. if (bitmaps[3] != null)
  1872. {
  1873. graph.DrawImage(bitmaps[3], everyRowWidth[0] + int.Parse(this.textBox1.Text), onePicHeight + int.Parse(this.textBox1.Text));
  1874. }
  1875. break;
  1876. case 6:
  1877. if (bitmaps[0] != null)
  1878. {
  1879. graph.DrawImage(bitmaps[0], 0, 0);
  1880. }
  1881. if (bitmaps[1] != null)
  1882. {
  1883. graph.DrawImage(bitmaps[1], everyRowWidth[0] + int.Parse(this.textBox1.Text), 0);
  1884. }
  1885. if (bitmaps[2] != null)
  1886. {
  1887. graph.DrawImage(bitmaps[2], everyRowWidth[0] + everyRowWidth[1] + int.Parse(this.textBox1.Text) * 2, 0);
  1888. }
  1889. if (bitmaps[3] != null)
  1890. {
  1891. graph.DrawImage(bitmaps[3], 0, onePicHeight + int.Parse(this.textBox1.Text));
  1892. }
  1893. if (bitmaps[4] != null)
  1894. {
  1895. graph.DrawImage(bitmaps[4], everyRowWidth[0] + int.Parse(this.textBox1.Text), onePicHeight + int.Parse(this.textBox1.Text));
  1896. }
  1897. if (bitmaps[5] != null)
  1898. {
  1899. graph.DrawImage(bitmaps[5], everyRowWidth[0] + everyRowWidth[1] + int.Parse(this.textBox1.Text) * 2, onePicHeight + int.Parse(this.textBox1.Text));
  1900. }
  1901. break;
  1902. case 8:
  1903. if (bitmaps[0] != null)
  1904. {
  1905. graph.DrawImage(bitmaps[0], 0, 0);
  1906. }
  1907. if (bitmaps[1] != null)
  1908. {
  1909. graph.DrawImage(bitmaps[1], everyRowWidth[0] + int.Parse(this.textBox1.Text), 0);
  1910. }
  1911. if (bitmaps[2] != null)
  1912. {
  1913. graph.DrawImage(bitmaps[2], everyRowWidth[0] + everyRowWidth[1] + int.Parse(this.textBox1.Text) * 2, 0);
  1914. }
  1915. if (bitmaps[3] != null)
  1916. {
  1917. graph.DrawImage(bitmaps[3], everyRowWidth[0] + everyRowWidth[1] + everyRowWidth[2] + int.Parse(this.textBox1.Text) * 3, 0);
  1918. }
  1919. if (bitmaps[4] != null)
  1920. {
  1921. graph.DrawImage(bitmaps[4], 0, onePicHeight + int.Parse(this.textBox1.Text));
  1922. }
  1923. if (bitmaps[5] != null)
  1924. {
  1925. graph.DrawImage(bitmaps[5], everyRowWidth[0] + int.Parse(this.textBox1.Text), onePicHeight + int.Parse(this.textBox1.Text));
  1926. }
  1927. if (bitmaps[6] != null)
  1928. {
  1929. graph.DrawImage(bitmaps[6], everyRowWidth[0] + everyRowWidth[1] + int.Parse(this.textBox1.Text) * 2, onePicHeight + int.Parse(this.textBox1.Text));
  1930. }
  1931. if (bitmaps[7] != null)
  1932. {
  1933. graph.DrawImage(bitmaps[7], everyRowWidth[0] + everyRowWidth[1] + everyRowWidth[2] + int.Parse(this.textBox1.Text) * 3, onePicHeight + int.Parse(this.textBox1.Text));
  1934. }
  1935. break;
  1936. case 9:
  1937. if (bitmaps[0] != null)
  1938. {
  1939. graph.DrawImage(bitmaps[0], 0, 0);
  1940. }
  1941. if (bitmaps[1] != null)
  1942. {
  1943. graph.DrawImage(bitmaps[1], everyRowWidth[0] + int.Parse(this.textBox1.Text), 0);
  1944. }
  1945. if (bitmaps[2] != null)
  1946. {
  1947. graph.DrawImage(bitmaps[2], everyRowWidth[0] + everyRowWidth[1] + int.Parse(this.textBox1.Text) * 2, 0);
  1948. }
  1949. if (bitmaps[3] != null)
  1950. {
  1951. graph.DrawImage(bitmaps[3], 0, onePicHeight + int.Parse(this.textBox1.Text));
  1952. }
  1953. if (bitmaps[4] != null)
  1954. {
  1955. graph.DrawImage(bitmaps[4], everyRowWidth[0] + int.Parse(this.textBox1.Text), onePicHeight + int.Parse(this.textBox1.Text));
  1956. }
  1957. if (bitmaps[5] != null)
  1958. {
  1959. graph.DrawImage(bitmaps[5], everyRowWidth[0] + everyRowWidth[1] + int.Parse(this.textBox1.Text) * 2, onePicHeight + int.Parse(this.textBox1.Text));
  1960. }
  1961. if (bitmaps[6] != null)
  1962. {
  1963. graph.DrawImage(bitmaps[6], 0, onePicHeight * 2 + int.Parse(this.textBox1.Text) * 2);
  1964. }
  1965. if (bitmaps[7] != null)
  1966. {
  1967. graph.DrawImage(bitmaps[7], everyRowWidth[0] + int.Parse(this.textBox1.Text), onePicHeight * 2 + int.Parse(this.textBox1.Text) * 2);
  1968. }
  1969. if (bitmaps[8] != null)
  1970. {
  1971. graph.DrawImage(bitmaps[8], everyRowWidth[0] + everyRowWidth[1] + int.Parse(this.textBox1.Text) * 2, onePicHeight * 2 + int.Parse(this.textBox1.Text) * 2);
  1972. }
  1973. break;
  1974. }
  1975. return bmp;
  1976. }
  1977. private void panel2Changed(object sender, EventArgs e)
  1978. {
  1979. this.panel2.BackColor = this.colorsForm.UserPrimaryColor.ToColor();
  1980. this.colorsForm.Close();
  1981. }
  1982. /// <summary>
  1983. /// 窗口大小改变
  1984. /// </summary>
  1985. /// <param name="sender"></param>
  1986. /// <param name="e"></param>
  1987. private void panel1_Resize(object sender, EventArgs e)
  1988. {
  1989. lastPoint.X = 0;
  1990. lastPoint.Y = 0;
  1991. RefreshColcontrol();
  1992. refreshRectangle();
  1993. }
  1994. /// <summary>
  1995. /// 刷新picture的矩形框
  1996. /// </summary>
  1997. private void refreshRectangle()
  1998. {
  1999. isFirst = true;
  2000. for (int i = 0; i < listColControl.Count; i++)
  2001. {
  2002. if (this.listColControl[i].isSelect == true)
  2003. {
  2004. newColtrol = this.listColControl[i];
  2005. break;
  2006. }
  2007. }
  2008. if (newColtrol != null && newColtrol.workspaceWindow.CompositionSurface != null)
  2009. {
  2010. getRatioBetweenPanelWindowAndBitmap(newColtrol);
  2011. this.pictureBox1.Refresh();
  2012. }
  2013. }
  2014. /// <summary>
  2015. /// 通过document窗口与图片计算显示比例
  2016. /// </summary>
  2017. /// <param name="colControl"></param>
  2018. private void getRatioBetweenPanelWindowAndBitmap(ColControl colControl)
  2019. {
  2020. Size size = colControl.workspaceWindow.panel.ClientSize;
  2021. newBitmap = colControl.workspaceWindow.CompositionSurface.CreateAliasedBitmap();
  2022. int width = size.Width;
  2023. int height = size.Height;
  2024. widthRatio = (double)width / ((double)newBitmap.Width * colControl.workspaceWindow.ScaleRatio);
  2025. if (widthRatio > 1)
  2026. {
  2027. widthRatio = 1;
  2028. }
  2029. heightRatio = (double)height / ((double)newBitmap.Height * colControl.workspaceWindow.ScaleRatio);
  2030. if (heightRatio > 1)
  2031. {
  2032. heightRatio = 1;
  2033. }
  2034. }
  2035. /// <summary>
  2036. /// 点击图库按钮
  2037. /// </summary>
  2038. /// <param name="sender"></param>
  2039. /// <param name="e"></param>
  2040. private void colControlButton_Click(object sender, EventArgs e)
  2041. {
  2042. if (((Button)sender).Tag != null)
  2043. {
  2044. buttonNum = Convert.ToInt32(((Button)sender).Tag);
  2045. }
  2046. if (imagePickerDialog == null)
  2047. {
  2048. imagePickerDialog = new InterImagePickerDialog(this.appWorkspace);
  2049. imagePickerDialog.StartPosition = FormStartPosition.Manual;
  2050. imagePickerDialog.Left = ((Button)sender).Left + 12 + this.Left;
  2051. imagePickerDialog.Top = ((Button)sender).Bottom + 36 + this.Top;
  2052. imagePickerDialog.ValueChanged += new System.EventHandler(this.inputMat_ValueChanged);
  2053. imagePickerDialog.Show();
  2054. }
  2055. else
  2056. {
  2057. if (!imagePickerDialog.IsDisposed)
  2058. {
  2059. imagePickerDialog.WindowState = FormWindowState.Normal;
  2060. }
  2061. else
  2062. {
  2063. imagePickerDialog = new InterImagePickerDialog(this.appWorkspace);
  2064. imagePickerDialog.StartPosition = FormStartPosition.Manual;
  2065. imagePickerDialog.Left = ((Button)sender).Left + 12 + this.Left;
  2066. imagePickerDialog.Top = ((Button)sender).Bottom + 36 + this.Top;
  2067. imagePickerDialog.ValueChanged += new System.EventHandler(this.inputMat_ValueChanged);
  2068. imagePickerDialog.Show();
  2069. }
  2070. }
  2071. }
  2072. /// <summary>
  2073. /// 从图库选择待对照图片
  2074. /// </summary>
  2075. /// <param name="sender"></param>
  2076. /// <param name="e"></param>
  2077. private void inputMat_ValueChanged(object sender, EventArgs e)
  2078. {
  2079. if (sender is DocumentWorkspace)
  2080. {
  2081. this.newColtrol = listColControl[buttonNum - 1];
  2082. //原图
  2083. Bitmap primaryBitmap = ((DocumentWorkspace)sender).CompositionSurface.CreateAliasedBitmap();// CompositionSurface.CreateAliasedBitmap();
  2084. //克隆原图
  2085. Bitmap newBit = primaryBitmap.Clone(new Rectangle(0, 0, primaryBitmap.Width, primaryBitmap.Height), primaryBitmap.PixelFormat);
  2086. //新图(测量,标注,多相等信息带入)
  2087. Bitmap bitmap = ((DocumentWorkspace)sender).NewPanelBitmap(newBit);
  2088. Document document = Document.FromImage(bitmap);
  2089. if (((DocumentWorkspace)sender).phaseModels.Count > 0)
  2090. {
  2091. this.newColtrol.workspaceWindow.phaseModels.Add(((DocumentWorkspace)sender).AnalysisPhaseModel);//多相、二值
  2092. }
  2093. //this.newColtrol.workspaceWindow.GraphicsList = ((DocumentWorkspace)sender).GraphicsList;//测量、标注、多视场
  2094. string imgName = ((DocumentWorkspace)sender).GetFriendlyName();//图名名称
  2095. //暂时绘制出来获得尺寸
  2096. Graphics graphics = CreateGraphics();
  2097. string label_str = imgName;
  2098. string str = label_str;
  2099. SizeF sizeF = graphics.MeasureString(label_str, listColControl[buttonNum - 1].label.Font);
  2100. //判断图片名是否超过label长度
  2101. if (sizeF.Width >= listColControl[buttonNum - 1].label.Width - 10)
  2102. {
  2103. str = label_str.Substring(0, str.Length - 4);
  2104. sizeF = graphics.MeasureString(str, listColControl[buttonNum - 1].label.Font);
  2105. listColControl[buttonNum - 1].label.Text = str + "...";
  2106. }
  2107. else
  2108. {
  2109. listColControl[buttonNum - 1].label.Text = str;
  2110. }
  2111. listColControl[buttonNum - 1].workspaceWindow.Document = document;
  2112. listColControl[buttonNum - 1].workspaceWindow.ZoomBasis = ZoomBasis.ScaleFactor;
  2113. //重置缩放比
  2114. listColControl[buttonNum - 1].workspaceWindow.ScaleFactor = new ScaleFactor(10, 100);
  2115. listColControl[buttonNum - 1].workspaceWindow.ScaleFactor = new ScaleFactor(100, 100);
  2116. listColControl[buttonNum - 1].workspaceWindow.Visible = true;
  2117. if (listColControl[buttonNum - 1].isSelect)
  2118. {
  2119. ColControl_Click(listColControl[buttonNum - 1], EventArgs.Empty);
  2120. }
  2121. }
  2122. }
  2123. public Bitmap DeepClone(Bitmap bitmap)
  2124. {
  2125. Bitmap dstBitmap = null;
  2126. using (MemoryStream mStream = new MemoryStream())
  2127. {
  2128. BinaryFormatter bf = new BinaryFormatter();
  2129. bf.Serialize(mStream, bitmap);
  2130. mStream.Seek(0, SeekOrigin.Begin);//指定当前流的位置为流的开头。
  2131. dstBitmap = (Bitmap)bf.Deserialize(mStream);
  2132. mStream.Close();
  2133. }
  2134. return dstBitmap;
  2135. }
  2136. /// <summary>
  2137. /// 点击自定义控件
  2138. /// </summary>
  2139. /// <param name="sender"></param>
  2140. /// <param name="e"></param>
  2141. private void ColControl_Click(object sender, EventArgs e)
  2142. {
  2143. isFirst = true;
  2144. if (sender is ColControl)
  2145. {
  2146. colNum = Convert.ToInt32(((ColControl)sender).Tag);//判断选中的是哪个控件
  2147. }
  2148. else if (sender is Panel)
  2149. {
  2150. colNum = Convert.ToInt32(((Panel)sender).Tag);//判断选中的是哪个控件
  2151. }
  2152. else if (sender is Ruler)
  2153. {
  2154. colNum = Convert.ToInt32(((Ruler)sender).Tag);//判断选中的是哪个控件
  2155. }
  2156. else if (sender is Button)
  2157. {
  2158. colNum = Convert.ToInt32(((Button)sender).Tag);//判断选中的是哪个控件
  2159. buttonNum = Convert.ToInt32(((Button)sender).Tag);
  2160. if (imagePickerDialog == null)
  2161. {
  2162. imagePickerDialog = new InterImagePickerDialog(this.appWorkspace);
  2163. imagePickerDialog.StartPosition = FormStartPosition.Manual;
  2164. imagePickerDialog.Left = ((Button)sender).Left + 12 + this.Left;
  2165. imagePickerDialog.Top = ((Button)sender).Bottom + 36 + this.Top;
  2166. imagePickerDialog.ValueChanged += new System.EventHandler(this.inputMat_ValueChanged);
  2167. imagePickerDialog.Show();
  2168. }
  2169. else
  2170. {
  2171. if (!imagePickerDialog.IsDisposed)
  2172. {
  2173. imagePickerDialog.WindowState = FormWindowState.Normal;
  2174. }
  2175. else
  2176. {
  2177. imagePickerDialog = new InterImagePickerDialog(this.appWorkspace);
  2178. imagePickerDialog.StartPosition = FormStartPosition.Manual;
  2179. imagePickerDialog.Left = ((Button)sender).Left + 12 + this.Left;
  2180. imagePickerDialog.Top = ((Button)sender).Bottom + 36 + this.Top;
  2181. imagePickerDialog.ValueChanged += new System.EventHandler(this.inputMat_ValueChanged);
  2182. imagePickerDialog.Show();
  2183. }
  2184. }
  2185. }
  2186. for (int i = 0; i < listColControl.Count; i++)
  2187. {
  2188. this.listColControl[i].isSelect = false;
  2189. }
  2190. this.listColControl[colNum - 1].isSelect = true;
  2191. this.panel1.Refresh();
  2192. newColtrol = this.listColControl[colNum - 1];
  2193. if (this.listColControl[colNum - 1].workspaceWindow.CompositionSurface != null)
  2194. {
  2195. getRatioBetweenPanelWindowAndBitmap(this.listColControl[colNum - 1]);
  2196. if (newBitmap.Width > pictureBox1.Size.Width || newBitmap.Height > pictureBox1.Size.Height)
  2197. {
  2198. pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
  2199. }
  2200. else
  2201. {
  2202. pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
  2203. }
  2204. this.pictureBox1.Image = newBitmap;
  2205. this.pictureBox1.Paint += new PaintEventHandler(pictureBox1_Paint);
  2206. }
  2207. else
  2208. {
  2209. this.pictureBox1.Image = null;
  2210. this.textBox2.Text = null;
  2211. }
  2212. }
  2213. /// <summary>
  2214. /// picturebox绘制矩形选中区域
  2215. /// </summary>
  2216. /// <param name="sender"></param>
  2217. /// <param name="e"></param>
  2218. private void pictureBox1_Paint(object sender, PaintEventArgs e)
  2219. {
  2220. if (this.pictureBox1.Image != null)
  2221. {
  2222. if (isFirst)
  2223. {
  2224. //获取缩略图对应矩形
  2225. PropertyInfo _ImageRectanglePropert = this.pictureBox1.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic);
  2226. imageRect = (Rectangle)_ImageRectanglePropert.GetValue(this.pictureBox1, null);
  2227. Point scPoint = newColtrol.workspaceWindow.PanelScrollPosition;//当前滚动条位置
  2228. double scRatioWidth = imageRect.Width / (newBitmap.Width * newColtrol.workspaceWindow.ScaleRatio);
  2229. double scRatioHeight = imageRect.Height / (newBitmap.Height * newColtrol.workspaceWindow.ScaleRatio);
  2230. //缩略图中红框选中区域
  2231. zoomRect = new Rectangle(imageRect.X + Convert.ToInt32(scPoint.X * scRatioWidth), imageRect.Y + Convert.ToInt32(scPoint.Y * scRatioHeight),
  2232. (int)(Math.Round(imageRect.Width * widthRatio)), (int)(Math.Round(imageRect.Height * heightRatio)));
  2233. //红框矩形的最小尺寸,即原图放大3200%
  2234. Size size = newColtrol.workspaceWindow.panel.ClientSize;
  2235. double minWidthRatio = size.Width / (newBitmap.Width * 32d);
  2236. double minHeightRatio = size.Height / (newBitmap.Height * 32d);
  2237. minRectWidth = (int)(Math.Round(imageRect.Width * minWidthRatio));
  2238. minRectHeight = (int)(Math.Round(imageRect.Height * minHeightRatio));
  2239. }
  2240. e.Graphics.DrawRectangle(new Pen(Color.Red), zoomRect.X, zoomRect.Y, zoomRect.Width - 1, zoomRect.Height - 1);
  2241. e.Graphics.FillRectangle(new SolidBrush(Color.Black), new Rectangle(zoomRect.Right - 3, zoomRect.Bottom - 3, 7, 7));
  2242. this.textBox2.Text = Math.Round(newColtrol.workspaceWindow.ScaleFactor.Ratio * 100) + "%";
  2243. this.textBox2.Refresh();
  2244. }
  2245. }
  2246. /// <summary>
  2247. /// 移动滚动条改变picture矩形框位置
  2248. /// </summary>
  2249. /// <param name="sender"></param>
  2250. /// <param name="e"></param>
  2251. private void scrollMovePictureBox(object sender, System.Windows.Forms.ScrollEventArgs e)
  2252. {
  2253. PanelEx panelEx = (PanelEx)sender;
  2254. ColControl colControl = (ColControl)panelEx.Parent.Parent.Parent;
  2255. int tag = (int)colControl.Tag;
  2256. if (this.pictureBox1.Image != null && colControl.isSelect)
  2257. {
  2258. //用自带的接口精度有问题
  2259. //int oldPosition = e.OldValue;
  2260. //int newPosition = e.NewValue;
  2261. //int rectPosition = newPosition - oldPosition;
  2262. Point scPoint = listColControl[tag - 1].workspaceWindow.PanelScrollPosition;
  2263. var whichScroll = e.ScrollOrientation;
  2264. double widthRatio2 = (double)imageRect.Width / ((double)newBitmap.Width * listColControl[tag - 1].workspaceWindow.ScaleRatio);
  2265. double heightRatio2 = (double)imageRect.Height / ((double)newBitmap.Height * listColControl[tag - 1].workspaceWindow.ScaleRatio);
  2266. //水平滚动条
  2267. if (whichScroll is System.Windows.Forms.ScrollOrientation.HorizontalScroll)
  2268. {
  2269. zoomRect.X = imageRect.X + Convert.ToInt32(Math.Round((double)scPoint.X * widthRatio2));
  2270. }
  2271. //垂直滚动条
  2272. if (whichScroll is System.Windows.Forms.ScrollOrientation.VerticalScroll)
  2273. {
  2274. zoomRect.Y = imageRect.Y + Convert.ToInt32(Math.Round((double)scPoint.Y * heightRatio2));
  2275. }
  2276. //copyRect = new Rectangle(zoomRect.X, zoomRect.Y, copyRect.Width, copyRect.Height);//是否要刷新100%的矩形位置
  2277. this.pictureBox1.Refresh();
  2278. }
  2279. }
  2280. /// <summary>
  2281. /// 从大图中截取一部分图片
  2282. /// </summary>
  2283. /// <param name="fromImage">来源图片</param>
  2284. /// <param name="offsetX">从偏移X坐标位置开始截取</param>
  2285. /// <param name="offsetY">从偏移Y坐标位置开始截取</param>
  2286. /// <param name="width">保存图片的宽度</param>
  2287. /// <param name="height">保存图片的高度</param>
  2288. /// <returns></returns>
  2289. public Bitmap CaptureImage(Bitmap fromImage, int offsetX, int offsetY, int width, int height)
  2290. {
  2291. //创建新图位图
  2292. Bitmap bitmap = new Bitmap(width, height);
  2293. //创建作图区域
  2294. Graphics graphic = Graphics.FromImage(bitmap);
  2295. //截取原图相应区域写入作图区
  2296. graphic.DrawImage(fromImage, 0, 0, new Rectangle(offsetX, offsetY, width, height), GraphicsUnit.Pixel);
  2297. //从作图区生成新图
  2298. Bitmap saveImage = Bitmap.FromHbitmap(bitmap.GetHbitmap());
  2299. return saveImage;
  2300. ////释放资源
  2301. //saveImage.Dispose();
  2302. //graphic.Dispose();
  2303. //bitmap.Dispose();
  2304. }
  2305. }
  2306. }