ColumnsShowDialog.cs 122 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496
  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.FromImageMat(Camera.Tools.ToMat(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.GraphicsList = ((DocumentWorkspace)sender).GraphicsList;
  2113. listColControl[buttonNum - 1].workspaceWindow.ZoomBasis = ZoomBasis.ScaleFactor;
  2114. //重置缩放比
  2115. listColControl[buttonNum - 1].workspaceWindow.ScaleFactor = new ScaleFactor(10, 100);
  2116. listColControl[buttonNum - 1].workspaceWindow.ScaleFactor = new ScaleFactor(100, 100);
  2117. listColControl[buttonNum - 1].workspaceWindow.Visible = true;
  2118. if (listColControl[buttonNum - 1].isSelect)
  2119. {
  2120. ColControl_Click(listColControl[buttonNum - 1], EventArgs.Empty);
  2121. }
  2122. }
  2123. }
  2124. public Bitmap DeepClone(Bitmap bitmap)
  2125. {
  2126. Bitmap dstBitmap = null;
  2127. using (MemoryStream mStream = new MemoryStream())
  2128. {
  2129. BinaryFormatter bf = new BinaryFormatter();
  2130. bf.Serialize(mStream, bitmap);
  2131. mStream.Seek(0, SeekOrigin.Begin);//指定当前流的位置为流的开头。
  2132. dstBitmap = (Bitmap)bf.Deserialize(mStream);
  2133. mStream.Close();
  2134. }
  2135. return dstBitmap;
  2136. }
  2137. /// <summary>
  2138. /// 点击自定义控件
  2139. /// </summary>
  2140. /// <param name="sender"></param>
  2141. /// <param name="e"></param>
  2142. private void ColControl_Click(object sender, EventArgs e)
  2143. {
  2144. isFirst = true;
  2145. if (sender is ColControl)
  2146. {
  2147. colNum = Convert.ToInt32(((ColControl)sender).Tag);//判断选中的是哪个控件
  2148. }
  2149. else if (sender is Panel)
  2150. {
  2151. colNum = Convert.ToInt32(((Panel)sender).Tag);//判断选中的是哪个控件
  2152. }
  2153. else if (sender is Ruler)
  2154. {
  2155. colNum = Convert.ToInt32(((Ruler)sender).Tag);//判断选中的是哪个控件
  2156. }
  2157. else if (sender is Button)
  2158. {
  2159. colNum = Convert.ToInt32(((Button)sender).Tag);//判断选中的是哪个控件
  2160. buttonNum = Convert.ToInt32(((Button)sender).Tag);
  2161. if (imagePickerDialog == null)
  2162. {
  2163. imagePickerDialog = new InterImagePickerDialog(this.appWorkspace);
  2164. imagePickerDialog.StartPosition = FormStartPosition.Manual;
  2165. imagePickerDialog.Left = ((Button)sender).Left + 12 + this.Left;
  2166. imagePickerDialog.Top = ((Button)sender).Bottom + 36 + this.Top;
  2167. imagePickerDialog.ValueChanged += new System.EventHandler(this.inputMat_ValueChanged);
  2168. imagePickerDialog.Show();
  2169. }
  2170. else
  2171. {
  2172. if (!imagePickerDialog.IsDisposed)
  2173. {
  2174. imagePickerDialog.WindowState = FormWindowState.Normal;
  2175. }
  2176. else
  2177. {
  2178. imagePickerDialog = new InterImagePickerDialog(this.appWorkspace);
  2179. imagePickerDialog.StartPosition = FormStartPosition.Manual;
  2180. imagePickerDialog.Left = ((Button)sender).Left + 12 + this.Left;
  2181. imagePickerDialog.Top = ((Button)sender).Bottom + 36 + this.Top;
  2182. imagePickerDialog.ValueChanged += new System.EventHandler(this.inputMat_ValueChanged);
  2183. imagePickerDialog.Show();
  2184. }
  2185. }
  2186. }
  2187. for (int i = 0; i < listColControl.Count; i++)
  2188. {
  2189. this.listColControl[i].isSelect = false;
  2190. }
  2191. this.listColControl[colNum - 1].isSelect = true;
  2192. this.panel1.Refresh();
  2193. newColtrol = this.listColControl[colNum - 1];
  2194. if (this.listColControl[colNum - 1].workspaceWindow.CompositionSurface != null)
  2195. {
  2196. getRatioBetweenPanelWindowAndBitmap(this.listColControl[colNum - 1]);
  2197. if (newBitmap.Width > pictureBox1.Size.Width || newBitmap.Height > pictureBox1.Size.Height)
  2198. {
  2199. pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
  2200. }
  2201. else
  2202. {
  2203. pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
  2204. }
  2205. this.pictureBox1.Image = newBitmap;
  2206. this.pictureBox1.Paint += new PaintEventHandler(pictureBox1_Paint);
  2207. }
  2208. else
  2209. {
  2210. this.pictureBox1.Image = null;
  2211. this.textBox2.Text = null;
  2212. }
  2213. }
  2214. /// <summary>
  2215. /// picturebox绘制矩形选中区域
  2216. /// </summary>
  2217. /// <param name="sender"></param>
  2218. /// <param name="e"></param>
  2219. private void pictureBox1_Paint(object sender, PaintEventArgs e)
  2220. {
  2221. if (this.pictureBox1.Image != null)
  2222. {
  2223. if (isFirst)
  2224. {
  2225. //获取缩略图对应矩形
  2226. PropertyInfo _ImageRectanglePropert = this.pictureBox1.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic);
  2227. imageRect = (Rectangle)_ImageRectanglePropert.GetValue(this.pictureBox1, null);
  2228. Point scPoint = newColtrol.workspaceWindow.PanelScrollPosition;//当前滚动条位置
  2229. double scRatioWidth = imageRect.Width / (newBitmap.Width * newColtrol.workspaceWindow.ScaleRatio);
  2230. double scRatioHeight = imageRect.Height / (newBitmap.Height * newColtrol.workspaceWindow.ScaleRatio);
  2231. //缩略图中红框选中区域
  2232. zoomRect = new Rectangle(imageRect.X + Convert.ToInt32(scPoint.X * scRatioWidth), imageRect.Y + Convert.ToInt32(scPoint.Y * scRatioHeight),
  2233. (int)(Math.Round(imageRect.Width * widthRatio)), (int)(Math.Round(imageRect.Height * heightRatio)));
  2234. //红框矩形的最小尺寸,即原图放大3200%
  2235. Size size = newColtrol.workspaceWindow.panel.ClientSize;
  2236. double minWidthRatio = size.Width / (newBitmap.Width * 32d);
  2237. double minHeightRatio = size.Height / (newBitmap.Height * 32d);
  2238. minRectWidth = (int)(Math.Round(imageRect.Width * minWidthRatio));
  2239. minRectHeight = (int)(Math.Round(imageRect.Height * minHeightRatio));
  2240. }
  2241. e.Graphics.DrawRectangle(new Pen(Color.Red), zoomRect.X, zoomRect.Y, zoomRect.Width - 1, zoomRect.Height - 1);
  2242. e.Graphics.FillRectangle(new SolidBrush(Color.Black), new Rectangle(zoomRect.Right - 3, zoomRect.Bottom - 3, 7, 7));
  2243. this.textBox2.Text = Math.Round(newColtrol.workspaceWindow.ScaleFactor.Ratio * 100) + "%";
  2244. this.textBox2.Refresh();
  2245. }
  2246. }
  2247. /// <summary>
  2248. /// 移动滚动条改变picture矩形框位置
  2249. /// </summary>
  2250. /// <param name="sender"></param>
  2251. /// <param name="e"></param>
  2252. private void scrollMovePictureBox(object sender, System.Windows.Forms.ScrollEventArgs e)
  2253. {
  2254. PanelEx panelEx = (PanelEx)sender;
  2255. ColControl colControl = (ColControl)panelEx.Parent.Parent.Parent;
  2256. int tag = (int)colControl.Tag;
  2257. if (this.pictureBox1.Image != null && colControl.isSelect)
  2258. {
  2259. //用自带的接口精度有问题
  2260. //int oldPosition = e.OldValue;
  2261. //int newPosition = e.NewValue;
  2262. //int rectPosition = newPosition - oldPosition;
  2263. Point scPoint = listColControl[tag - 1].workspaceWindow.PanelScrollPosition;
  2264. var whichScroll = e.ScrollOrientation;
  2265. double widthRatio2 = (double)imageRect.Width / ((double)newBitmap.Width * listColControl[tag - 1].workspaceWindow.ScaleRatio);
  2266. double heightRatio2 = (double)imageRect.Height / ((double)newBitmap.Height * listColControl[tag - 1].workspaceWindow.ScaleRatio);
  2267. //水平滚动条
  2268. if (whichScroll is System.Windows.Forms.ScrollOrientation.HorizontalScroll)
  2269. {
  2270. zoomRect.X = imageRect.X + Convert.ToInt32(Math.Round((double)scPoint.X * widthRatio2));
  2271. }
  2272. //垂直滚动条
  2273. if (whichScroll is System.Windows.Forms.ScrollOrientation.VerticalScroll)
  2274. {
  2275. zoomRect.Y = imageRect.Y + Convert.ToInt32(Math.Round((double)scPoint.Y * heightRatio2));
  2276. }
  2277. //copyRect = new Rectangle(zoomRect.X, zoomRect.Y, copyRect.Width, copyRect.Height);//是否要刷新100%的矩形位置
  2278. this.pictureBox1.Refresh();
  2279. }
  2280. }
  2281. /// <summary>
  2282. /// 从大图中截取一部分图片
  2283. /// </summary>
  2284. /// <param name="fromImage">来源图片</param>
  2285. /// <param name="offsetX">从偏移X坐标位置开始截取</param>
  2286. /// <param name="offsetY">从偏移Y坐标位置开始截取</param>
  2287. /// <param name="width">保存图片的宽度</param>
  2288. /// <param name="height">保存图片的高度</param>
  2289. /// <returns></returns>
  2290. public Bitmap CaptureImage(Bitmap fromImage, int offsetX, int offsetY, int width, int height)
  2291. {
  2292. //创建新图位图
  2293. Bitmap bitmap = new Bitmap(width, height);
  2294. //创建作图区域
  2295. Graphics graphic = Graphics.FromImage(bitmap);
  2296. //截取原图相应区域写入作图区
  2297. graphic.DrawImage(fromImage, 0, 0, new Rectangle(offsetX, offsetY, width, height), GraphicsUnit.Pixel);
  2298. //从作图区生成新图
  2299. Bitmap saveImage = Bitmap.FromHbitmap(bitmap.GetHbitmap());
  2300. return saveImage;
  2301. ////释放资源
  2302. //saveImage.Dispose();
  2303. //graphic.Dispose();
  2304. //bitmap.Dispose();
  2305. }
  2306. }
  2307. }