ImageMosaicsDialog.cs 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493
  1. using PaintDotNet.Adjust;
  2. using PaintDotNet.Base.CommTool;
  3. using PaintDotNet.Processing.DepthExtensionComponent;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Reflection;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. namespace PaintDotNet.Processing
  15. {
  16. /// <summary>
  17. /// 图像拼接
  18. /// </summary>
  19. internal class ImageMosaicsDialog : PdnBaseForm
  20. {
  21. private Button button1;
  22. private Button button3;
  23. private Button button2;
  24. private Button button4;
  25. private Button button5;
  26. private GroupBox groupBox2;
  27. private Label label1;
  28. private TextBox tbxColunmN;
  29. private Label label2;
  30. private TextBox textBox2;
  31. private GroupBox groupBox3;
  32. private Panel panel1;
  33. private GroupBox groupBox1;
  34. private GroupBox groupBoxStep2Operate;
  35. private Button btnFromFile;
  36. private Button btnFromApp;
  37. private GroupBox groupBox5;
  38. private Panel panel2;
  39. private GroupBox groupBox6;
  40. private GroupBox groupBox7;
  41. private Button button8;
  42. private TextBox textBox3;
  43. private Label label3;
  44. private PictureBox pictureBox1;
  45. private AppWorkspace appWorkspace;
  46. /// <summary>
  47. /// 是否重置picturebox中的矩形尺寸
  48. /// </summary>
  49. private bool _isFirst = true;
  50. /// <summary>
  51. /// 是否为拖动picturebox中的矩形框
  52. /// </summary>
  53. private bool isMoved = false;
  54. /// <summary>
  55. /// 是否为修改picturebox中的矩形框大小
  56. /// </summary>
  57. private bool isResized = false;
  58. /// <summary>
  59. /// 辅助计算偏移量
  60. /// </summary>
  61. private Point _lastPoint = new Point(0, 0);
  62. /// <summary>
  63. /// picturebox中图片对应矩形
  64. /// </summary>
  65. private Rectangle imageRect;
  66. /// <summary>
  67. /// picturebox中选择框对应矩形
  68. /// </summary>
  69. private Rectangle zoomRect;
  70. /// <summary>
  71. /// 命名
  72. /// </summary>
  73. private string stepNumber = "001";
  74. /// <summary>
  75. /// 图片选择窗口
  76. /// </summary>
  77. private InterImagePickerDialog imagePickerDialog;
  78. /// <summary>
  79. /// 拼接后的图片
  80. /// </summary>
  81. private Bitmap _mosaicsImage;
  82. /// <summary>
  83. /// 图片自定义控件判断鼠标是否按下
  84. /// </summary>
  85. private bool isMouseDown = false;
  86. /// <summary>
  87. /// 自定义控件的location
  88. /// </summary>
  89. private Point picToolLocation;
  90. /// <summary>
  91. /// 鼠标的按下位置
  92. /// </summary>
  93. private Point mouseOffset;
  94. /// <summary>
  95. /// 控件拖动前的location
  96. /// </summary>
  97. private Point oldToolLocation;
  98. private Label label4;
  99. private NumericUpDown numOverlapRate;
  100. /// <summary>
  101. /// 控件拖动前的tag值
  102. /// </summary>
  103. private int oldToolTag;
  104. public ImageMosaicsDialog(AppWorkspace appWorkspace)
  105. {
  106. this.appWorkspace = appWorkspace;
  107. InitializeComponent();
  108. InitializeLanguageText();
  109. InitializeOtherInfo();
  110. AddPitureboxTools();
  111. ReloadStepTwoControls();
  112. }
  113. private void InitializeLanguageText()
  114. {
  115. this.button3.Text = PdnResources.GetString("Menu.thirdstep.text");
  116. this.button4.Text = PdnResources.GetString("Menu.Nextstep.text");
  117. this.button5.Text = PdnResources.GetString("Menu.return.text");
  118. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  119. this.button2.Text = PdnResources.GetString("Menu.Secondstep.text");
  120. this.button1.Text = PdnResources.GetString("Menu.firststep.text");
  121. this.groupBox2.Text = PdnResources.GetString("Menu.Setting.Text");
  122. this.label2.Text = PdnResources.GetString("Menu.ImageProcessing.Imagestitching.Thenumberofvertical.text") + ":";
  123. this.label1.Text = PdnResources.GetString("Menu.ImageProcessing.Imagestitching.Thelevelofthenumber.text") + ":";
  124. this.groupBox3.Text = PdnResources.GetString("Menu.Preview.text");
  125. this.groupBoxStep2Operate.Text = PdnResources.GetString("Menu.Selectpicturefrom.text");
  126. this.btnFromFile.Text = PdnResources.GetString("Menu.Harddiskfile.text");
  127. this.btnFromApp.Text = PdnResources.GetString("Menu.Currentsoftware.text");
  128. this.groupBox5.Text = PdnResources.GetString("Menu.Preview.text");
  129. this.groupBox6.Text = PdnResources.GetString("Menu.finish.text");
  130. this.button8.Text = PdnResources.GetString("Menu.File.Save.Text");
  131. this.label3.Text = PdnResources.GetString("Menu.Imagename.text") + ":";
  132. this.groupBox7.Text = PdnResources.GetString("Menu.Preview.text");
  133. this.Text = PdnResources.GetString("Menu.ImageCollection.ImageStitching.Text");
  134. }
  135. /// <summary>
  136. /// 初始化基础控件
  137. /// </summary>
  138. private void InitializeComponent()
  139. {
  140. this.groupBox1 = new System.Windows.Forms.GroupBox();
  141. this.button5 = new System.Windows.Forms.Button();
  142. this.button4 = new System.Windows.Forms.Button();
  143. this.button3 = new System.Windows.Forms.Button();
  144. this.button2 = new System.Windows.Forms.Button();
  145. this.button1 = new System.Windows.Forms.Button();
  146. this.groupBox2 = new System.Windows.Forms.GroupBox();
  147. this.textBox2 = new System.Windows.Forms.TextBox();
  148. this.tbxColunmN = new System.Windows.Forms.TextBox();
  149. this.label2 = new System.Windows.Forms.Label();
  150. this.label1 = new System.Windows.Forms.Label();
  151. this.groupBox3 = new System.Windows.Forms.GroupBox();
  152. this.panel1 = new System.Windows.Forms.Panel();
  153. this.groupBoxStep2Operate = new System.Windows.Forms.GroupBox();
  154. this.numOverlapRate = new System.Windows.Forms.NumericUpDown();
  155. this.label4 = new System.Windows.Forms.Label();
  156. this.btnFromFile = new System.Windows.Forms.Button();
  157. this.btnFromApp = new System.Windows.Forms.Button();
  158. this.groupBox5 = new System.Windows.Forms.GroupBox();
  159. this.panel2 = new System.Windows.Forms.Panel();
  160. this.groupBox6 = new System.Windows.Forms.GroupBox();
  161. this.button8 = new System.Windows.Forms.Button();
  162. this.textBox3 = new System.Windows.Forms.TextBox();
  163. this.label3 = new System.Windows.Forms.Label();
  164. this.groupBox7 = new System.Windows.Forms.GroupBox();
  165. this.pictureBox1 = new System.Windows.Forms.PictureBox();
  166. this.groupBox1.SuspendLayout();
  167. this.groupBox2.SuspendLayout();
  168. this.groupBox3.SuspendLayout();
  169. this.groupBoxStep2Operate.SuspendLayout();
  170. ((System.ComponentModel.ISupportInitialize)(this.numOverlapRate)).BeginInit();
  171. this.groupBox5.SuspendLayout();
  172. this.groupBox6.SuspendLayout();
  173. this.groupBox7.SuspendLayout();
  174. ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
  175. this.SuspendLayout();
  176. //
  177. // groupBox1
  178. //
  179. this.groupBox1.Controls.Add(this.button5);
  180. this.groupBox1.Controls.Add(this.button4);
  181. this.groupBox1.Controls.Add(this.button3);
  182. this.groupBox1.Controls.Add(this.button2);
  183. this.groupBox1.Controls.Add(this.button1);
  184. this.groupBox1.Location = new System.Drawing.Point(13, 13);
  185. this.groupBox1.Name = "groupBox1";
  186. this.groupBox1.Size = new System.Drawing.Size(88, 603);
  187. this.groupBox1.TabIndex = 0;
  188. this.groupBox1.TabStop = false;
  189. this.groupBox1.Text = "操作";
  190. //
  191. // button5
  192. //
  193. this.button5.Location = new System.Drawing.Point(6, 480);
  194. this.button5.Name = "button5";
  195. this.button5.Size = new System.Drawing.Size(75, 23);
  196. this.button5.TabIndex = 4;
  197. this.button5.Text = "返回";
  198. this.button5.UseVisualStyleBackColor = true;
  199. this.button5.Click += new System.EventHandler(this.button5_Click);
  200. //
  201. // button4
  202. //
  203. this.button4.Location = new System.Drawing.Point(6, 517);
  204. this.button4.Name = "button4";
  205. this.button4.Size = new System.Drawing.Size(75, 23);
  206. this.button4.TabIndex = 3;
  207. this.button4.Text = "下一步";
  208. this.button4.UseVisualStyleBackColor = true;
  209. this.button4.Click += new System.EventHandler(this.button4_Click);
  210. //
  211. // button3
  212. //
  213. this.button3.Location = new System.Drawing.Point(7, 124);
  214. this.button3.Name = "button3";
  215. this.button3.Size = new System.Drawing.Size(75, 23);
  216. this.button3.TabIndex = 2;
  217. this.button3.Text = "第三步";
  218. this.button3.UseVisualStyleBackColor = true;
  219. this.button3.Click += new System.EventHandler(this.button3_Click);
  220. //
  221. // button2
  222. //
  223. this.button2.Location = new System.Drawing.Point(7, 86);
  224. this.button2.Name = "button2";
  225. this.button2.Size = new System.Drawing.Size(75, 23);
  226. this.button2.TabIndex = 1;
  227. this.button2.Text = "第二步";
  228. this.button2.UseVisualStyleBackColor = true;
  229. this.button2.Click += new System.EventHandler(this.button2_Click);
  230. //
  231. // button1
  232. //
  233. this.button1.Location = new System.Drawing.Point(7, 48);
  234. this.button1.Name = "button1";
  235. this.button1.Size = new System.Drawing.Size(75, 23);
  236. this.button1.TabIndex = 0;
  237. this.button1.Text = "第一步";
  238. this.button1.UseVisualStyleBackColor = true;
  239. this.button1.Click += new System.EventHandler(this.button1_Click);
  240. //
  241. // groupBox2
  242. //
  243. this.groupBox2.Controls.Add(this.textBox2);
  244. this.groupBox2.Controls.Add(this.tbxColunmN);
  245. this.groupBox2.Controls.Add(this.label2);
  246. this.groupBox2.Controls.Add(this.label1);
  247. this.groupBox2.Location = new System.Drawing.Point(123, 13);
  248. this.groupBox2.Name = "groupBox2";
  249. this.groupBox2.Size = new System.Drawing.Size(623, 60);
  250. this.groupBox2.TabIndex = 1;
  251. this.groupBox2.TabStop = false;
  252. //
  253. // textBox2
  254. //
  255. this.textBox2.Location = new System.Drawing.Point(418, 22);
  256. this.textBox2.Name = "textBox2";
  257. this.textBox2.Size = new System.Drawing.Size(140, 21);
  258. this.textBox2.TabIndex = 3;
  259. this.textBox2.Text = "4";
  260. this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
  261. this.textBox2.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox2_KeyPress);
  262. //
  263. // tbxColunmN
  264. //
  265. this.tbxColunmN.Location = new System.Drawing.Point(117, 22);
  266. this.tbxColunmN.Name = "tbxColunmN";
  267. this.tbxColunmN.Size = new System.Drawing.Size(140, 21);
  268. this.tbxColunmN.TabIndex = 2;
  269. this.tbxColunmN.Text = "3";
  270. this.tbxColunmN.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
  271. this.tbxColunmN.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);
  272. //
  273. // label2
  274. //
  275. this.label2.AutoSize = true;
  276. this.label2.Location = new System.Drawing.Point(356, 26);
  277. this.label2.Name = "label2";
  278. this.label2.Size = new System.Drawing.Size(0, 12);
  279. this.label2.TabIndex = 1;
  280. //
  281. // label1
  282. //
  283. this.label1.AutoSize = true;
  284. this.label1.Location = new System.Drawing.Point(55, 26);
  285. this.label1.Name = "label1";
  286. this.label1.Size = new System.Drawing.Size(0, 12);
  287. this.label1.TabIndex = 0;
  288. //
  289. // groupBox3
  290. //
  291. this.groupBox3.Controls.Add(this.panel1);
  292. this.groupBox3.Location = new System.Drawing.Point(123, 89);
  293. this.groupBox3.Name = "groupBox3";
  294. this.groupBox3.Size = new System.Drawing.Size(623, 527);
  295. this.groupBox3.TabIndex = 2;
  296. this.groupBox3.TabStop = false;
  297. //
  298. // panel1
  299. //
  300. this.panel1.AutoScroll = true;
  301. this.panel1.BackColor = System.Drawing.Color.Transparent;
  302. this.panel1.Location = new System.Drawing.Point(6, 14);
  303. this.panel1.Name = "panel1";
  304. this.panel1.Size = new System.Drawing.Size(611, 507);
  305. this.panel1.TabIndex = 0;
  306. //
  307. // groupBoxStep2Operate
  308. //
  309. this.groupBoxStep2Operate.Controls.Add(this.numOverlapRate);
  310. this.groupBoxStep2Operate.Controls.Add(this.label4);
  311. this.groupBoxStep2Operate.Controls.Add(this.btnFromFile);
  312. this.groupBoxStep2Operate.Controls.Add(this.btnFromApp);
  313. this.groupBoxStep2Operate.Location = new System.Drawing.Point(123, 13);
  314. this.groupBoxStep2Operate.Name = "groupBoxStep2Operate";
  315. this.groupBoxStep2Operate.Size = new System.Drawing.Size(623, 60);
  316. this.groupBoxStep2Operate.TabIndex = 3;
  317. this.groupBoxStep2Operate.TabStop = false;
  318. //
  319. // numOverlapRate
  320. //
  321. this.numOverlapRate.DecimalPlaces = 2;
  322. this.numOverlapRate.Increment = new decimal(new int[] {
  323. 5,
  324. 0,
  325. 0,
  326. 131072});
  327. this.numOverlapRate.Location = new System.Drawing.Point(99, 23);
  328. this.numOverlapRate.Maximum = new decimal(new int[] {
  329. 1,
  330. 0,
  331. 0,
  332. 0});
  333. this.numOverlapRate.Minimum = new decimal(new int[] {
  334. 5,
  335. 0,
  336. 0,
  337. 131072});
  338. this.numOverlapRate.Name = "numOverlapRate";
  339. this.numOverlapRate.Size = new System.Drawing.Size(60, 21);
  340. this.numOverlapRate.TabIndex = 4;
  341. this.numOverlapRate.Value = new decimal(new int[] {
  342. 10,
  343. 0,
  344. 0,
  345. 131072});
  346. //
  347. // label4
  348. //
  349. this.label4.AutoSize = true;
  350. this.label4.Location = new System.Drawing.Point(16, 26);
  351. this.label4.Name = "label4";
  352. this.label4.Size = new System.Drawing.Size(77, 12);
  353. this.label4.TabIndex = 3;
  354. this.label4.Text = "Overlap rate";
  355. //
  356. // btnFromFile
  357. //
  358. this.btnFromFile.Location = new System.Drawing.Point(526, 20);
  359. this.btnFromFile.Name = "btnFromFile";
  360. this.btnFromFile.Size = new System.Drawing.Size(75, 23);
  361. this.btnFromFile.TabIndex = 1;
  362. this.btnFromFile.UseVisualStyleBackColor = true;
  363. this.btnFromFile.Click += new System.EventHandler(this.button7_Click);
  364. //
  365. // btnFromApp
  366. //
  367. this.btnFromApp.Location = new System.Drawing.Point(414, 20);
  368. this.btnFromApp.Name = "btnFromApp";
  369. this.btnFromApp.Size = new System.Drawing.Size(75, 23);
  370. this.btnFromApp.TabIndex = 0;
  371. this.btnFromApp.UseVisualStyleBackColor = true;
  372. this.btnFromApp.Click += new System.EventHandler(this.button6_Click);
  373. //
  374. // groupBox5
  375. //
  376. this.groupBox5.Controls.Add(this.panel2);
  377. this.groupBox5.Location = new System.Drawing.Point(123, 89);
  378. this.groupBox5.Name = "groupBox5";
  379. this.groupBox5.Size = new System.Drawing.Size(623, 527);
  380. this.groupBox5.TabIndex = 4;
  381. this.groupBox5.TabStop = false;
  382. //
  383. // panel2
  384. //
  385. this.panel2.AutoScroll = true;
  386. this.panel2.Location = new System.Drawing.Point(6, 14);
  387. this.panel2.Name = "panel2";
  388. this.panel2.Size = new System.Drawing.Size(611, 507);
  389. this.panel2.TabIndex = 0;
  390. //
  391. // groupBox6
  392. //
  393. this.groupBox6.Controls.Add(this.button8);
  394. this.groupBox6.Controls.Add(this.textBox3);
  395. this.groupBox6.Controls.Add(this.label3);
  396. this.groupBox6.Location = new System.Drawing.Point(123, 13);
  397. this.groupBox6.Name = "groupBox6";
  398. this.groupBox6.Size = new System.Drawing.Size(623, 60);
  399. this.groupBox6.TabIndex = 5;
  400. this.groupBox6.TabStop = false;
  401. this.groupBox6.Text = "设置";
  402. //
  403. // button8
  404. //
  405. this.button8.Location = new System.Drawing.Point(511, 20);
  406. this.button8.Name = "button8";
  407. this.button8.Size = new System.Drawing.Size(75, 23);
  408. this.button8.TabIndex = 2;
  409. this.button8.Text = "保存";
  410. this.button8.UseVisualStyleBackColor = true;
  411. this.button8.Click += new System.EventHandler(this.button8_Click);
  412. //
  413. // textBox3
  414. //
  415. this.textBox3.Location = new System.Drawing.Point(93, 22);
  416. this.textBox3.Name = "textBox3";
  417. this.textBox3.Size = new System.Drawing.Size(167, 21);
  418. this.textBox3.TabIndex = 1;
  419. //
  420. // label3
  421. //
  422. this.label3.AutoSize = true;
  423. this.label3.Location = new System.Drawing.Point(28, 25);
  424. this.label3.Name = "label3";
  425. this.label3.Size = new System.Drawing.Size(65, 12);
  426. this.label3.TabIndex = 0;
  427. this.label3.Text = "图像名称:";
  428. //
  429. // groupBox7
  430. //
  431. this.groupBox7.Controls.Add(this.pictureBox1);
  432. this.groupBox7.Location = new System.Drawing.Point(123, 89);
  433. this.groupBox7.Name = "groupBox7";
  434. this.groupBox7.Size = new System.Drawing.Size(623, 527);
  435. this.groupBox7.TabIndex = 6;
  436. this.groupBox7.TabStop = false;
  437. this.groupBox7.Text = "预览";
  438. //
  439. // pictureBox1
  440. //
  441. this.pictureBox1.Location = new System.Drawing.Point(6, 14);
  442. this.pictureBox1.Name = "pictureBox1";
  443. this.pictureBox1.Size = new System.Drawing.Size(611, 507);
  444. this.pictureBox1.TabIndex = 0;
  445. this.pictureBox1.TabStop = false;
  446. //
  447. // ImageMosaicsDialog
  448. //
  449. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  450. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
  451. this.ClientSize = new System.Drawing.Size(758, 628);
  452. this.Controls.Add(this.groupBox7);
  453. this.Controls.Add(this.groupBox5);
  454. this.Controls.Add(this.groupBox3);
  455. this.Controls.Add(this.groupBox2);
  456. this.Controls.Add(this.groupBox1);
  457. this.Controls.Add(this.groupBox6);
  458. this.Controls.Add(this.groupBoxStep2Operate);
  459. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  460. this.MaximizeBox = false;
  461. this.MinimizeBox = false;
  462. this.Name = "ImageMosaicsDialog";
  463. this.Text = "图像拼接";
  464. this.Controls.SetChildIndex(this.groupBoxStep2Operate, 0);
  465. this.Controls.SetChildIndex(this.groupBox6, 0);
  466. this.Controls.SetChildIndex(this.groupBox1, 0);
  467. this.Controls.SetChildIndex(this.groupBox2, 0);
  468. this.Controls.SetChildIndex(this.groupBox3, 0);
  469. this.Controls.SetChildIndex(this.groupBox5, 0);
  470. this.Controls.SetChildIndex(this.groupBox7, 0);
  471. this.groupBox1.ResumeLayout(false);
  472. this.groupBox2.ResumeLayout(false);
  473. this.groupBox2.PerformLayout();
  474. this.groupBox3.ResumeLayout(false);
  475. this.groupBoxStep2Operate.ResumeLayout(false);
  476. this.groupBoxStep2Operate.PerformLayout();
  477. ((System.ComponentModel.ISupportInitialize)(this.numOverlapRate)).EndInit();
  478. this.groupBox5.ResumeLayout(false);
  479. this.groupBox6.ResumeLayout(false);
  480. this.groupBox6.PerformLayout();
  481. this.groupBox7.ResumeLayout(false);
  482. ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
  483. this.ResumeLayout(false);
  484. }
  485. /// <summary>
  486. /// 初始化其他控件
  487. /// </summary>
  488. private void InitializeOtherInfo()
  489. {
  490. //第一次进入页面的"第一步"按钮样式
  491. this.button1.BackColor = Color.Gray;
  492. this.button1.ForeColor = Color.White;
  493. this.button1.FlatStyle = FlatStyle.Flat;
  494. this.button1.FlatAppearance.BorderSize = 0;
  495. this.groupBoxStep2Operate.Visible = false;
  496. this.groupBox5.Visible = false;
  497. this.groupBox6.Visible = false;
  498. this.groupBox7.Visible = false;
  499. this.pictureBox1.Paint += new PaintEventHandler(pictureBox1_Paint);
  500. this.pictureBox1.MouseDown += new MouseEventHandler(pictureBox1_MouseDown);
  501. this.pictureBox1.MouseMove += new MouseEventHandler(pictureBox1_MouseMove);
  502. }
  503. /// <summary>
  504. /// 加载空白图片控件
  505. /// </summary>
  506. private void AddPitureboxTools()
  507. {
  508. int colNum = this.tbxColunmN.Text == "" ? 0 : Convert.ToInt32(this.tbxColunmN.Text);//列数
  509. if (colNum == 0)
  510. {
  511. MessageBox.Show(PdnResources.GetString("Menu.henumberoflevelsisnotcorrecpleasereset.Text"));
  512. return;
  513. }
  514. int rowNum = this.textBox2.Text == "" ? 0 : Convert.ToInt32(this.textBox2.Text);//行数
  515. if (rowNum == 0)
  516. {
  517. MessageBox.Show(PdnResources.GetString("Menu.Theverticanumberisnotcorrectpleasereset.Text"));
  518. return;
  519. }
  520. Point startPoint = new Point(0, 4);
  521. if (colNum < 5)
  522. startPoint.X = (this.panel1.Width - (116 * colNum)) / (colNum + 1);
  523. int marginTB = 7;//固定的上下边距
  524. //滚动条不用处理,直接刷整个控件?
  525. for (int i = 0; i < colNum; i++)
  526. {
  527. for (int j = 0; j < rowNum; j++)
  528. {
  529. PictureBox pictureBox = new PictureBox();
  530. pictureBox.Size = new Size(116, 116);
  531. if (colNum >= 5)
  532. {
  533. pictureBox.Location = new Point((120 * i), startPoint.Y + ((116 + marginTB) * j));
  534. }
  535. else//水平数小于5时,边距是动态的
  536. pictureBox.Location = new Point(startPoint.X + ((startPoint.X + 116) * i), startPoint.Y + ((116 + marginTB) * j));
  537. pictureBox.BackColor = Color.White;
  538. this.panel1.Controls.Add(pictureBox);
  539. }
  540. }
  541. }
  542. /// <summary>
  543. /// 修改水平个数刷新panel
  544. /// </summary>
  545. /// <param name="sender"></param>
  546. /// <param name="e"></param>
  547. private void textBox1_TextChanged(object sender, EventArgs e)
  548. {
  549. if (tbxColunmN.Text.Trim() == "" || textBox2.Text.Trim() == "")
  550. {
  551. return;
  552. }
  553. //tbxColunmN.Invoke(new EventHandler(delegate {
  554. // tbxColunmN.Text = int.Parse(tbxColunmN.Text) * int.Parse(textBox2.Text) > 1000 ? (int)(1000 / int.Parse(textBox2.Text)) + "" : tbxColunmN.Text;
  555. //}));
  556. if (int.Parse(textBox2.Text) * int.Parse(tbxColunmN.Text) > 1000)
  557. {
  558. tbxColunmN.Text = (int)(1000 / int.Parse(textBox2.Text)) + "";
  559. return;
  560. }
  561. this.panel1.Controls.Clear();
  562. AddPitureboxTools();
  563. ReloadStepTwoControls();
  564. FocusToCaret(tbxColunmN);
  565. }
  566. /// <summary>
  567. /// 修改垂直个数刷新panel
  568. /// </summary>
  569. /// <param name="sender"></param>
  570. /// <param name="e"></param>
  571. private void textBox2_TextChanged(object sender, EventArgs e)
  572. {
  573. if (tbxColunmN.Text.Trim() == "" || textBox2.Text.Trim() == "")
  574. {
  575. return;
  576. }
  577. //textBox2.Invoke(new EventHandler(delegate {
  578. // textBox2.Text = int.Parse(textBox2.Text) * int.Parse(tbxColunmN.Text) > 1000 ? (int)(1000 / int.Parse(tbxColunmN.Text)) + "" : textBox2.Text;
  579. //}));
  580. if (int.Parse(textBox2.Text) * int.Parse(tbxColunmN.Text) > 1000)
  581. {
  582. textBox2.Text = (int)(1000 / int.Parse(tbxColunmN.Text)) + "";
  583. return;
  584. }
  585. this.panel1.Controls.Clear();
  586. AddPitureboxTools();
  587. ReloadStepTwoControls();
  588. FocusToCaret(textBox2);
  589. }
  590. /// <summary>
  591. /// 限制只可以输入0-9数字以及退格键
  592. /// </summary>
  593. /// <param name="sender"></param>
  594. /// <param name="e"></param>
  595. private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
  596. {
  597. if (e.KeyChar != '\b')//这是允许输入退格键 
  598.             {
  599. int len = this.tbxColunmN.Text.Length;
  600. if (len < 1 && e.KeyChar == '0')
  601. {
  602. e.Handled = true;
  603. }
  604. else if ((e.KeyChar < '0') || (e.KeyChar > '9'))//这是允许输入0-9数字 
  605.                 {
  606. e.Handled = true;
  607. }
  608. }
  609. }
  610. /// <summary>
  611. /// 限制只可以输入0-9数字以及退格键
  612. /// </summary>
  613. /// <param name="sender"></param>
  614. /// <param name="e"></param>
  615. private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
  616. {
  617. if (e.KeyChar != '\b')//这是允许输入退格键 
  618.             {
  619. int len = this.textBox2.Text.Length;
  620. if (len < 1 && e.KeyChar == '0')
  621. {
  622. e.Handled = true;
  623. }
  624. else if ((e.KeyChar < '0') || (e.KeyChar > '9'))//这是允许输入0-9数字 
  625.                 {
  626. e.Handled = true;
  627. }
  628. }
  629. }
  630. void FocusToCaret(TextBox txt)
  631. {
  632. txt.Focus();
  633. txt.Select(this.tbxColunmN.TextLength, 0);
  634. txt.ScrollToCaret();
  635. }
  636. /// <summary>
  637. /// 点击当前软件按钮
  638. /// </summary>
  639. /// <param name="sender"></param>
  640. /// <param name="e"></param>
  641. private void button6_Click(object sender, EventArgs e)
  642. {
  643. if (imagePickerDialog == null)
  644. {
  645. imagePickerDialog = new InterImagePickerDialog(this.appWorkspace);
  646. imagePickerDialog.StartPosition = FormStartPosition.Manual;
  647. imagePickerDialog.Left = ((Button)sender).Left + 12 + this.Left;
  648. imagePickerDialog.Top = ((Button)sender).Bottom + 36 + this.Top;
  649. imagePickerDialog.ValueChanged += new System.EventHandler(this.inputMat_ValueChanged);
  650. imagePickerDialog.Show();
  651. }
  652. else
  653. {
  654. if (!imagePickerDialog.IsDisposed)
  655. {
  656. imagePickerDialog.WindowState = FormWindowState.Normal;
  657. }
  658. else
  659. {
  660. imagePickerDialog = new InterImagePickerDialog(this.appWorkspace);
  661. imagePickerDialog.StartPosition = FormStartPosition.Manual;
  662. imagePickerDialog.Left = ((Button)sender).Left + 12 + this.Left;
  663. imagePickerDialog.Top = ((Button)sender).Bottom + 36 + this.Top;
  664. imagePickerDialog.ValueChanged += new System.EventHandler(this.inputMat_ValueChanged);
  665. imagePickerDialog.Show();
  666. }
  667. }
  668. }
  669. /// <summary>
  670. /// 从图库选择待对照图片
  671. /// </summary>
  672. /// <param name="sender"></param>
  673. /// <param name="e"></param>
  674. private void inputMat_ValueChanged(object sender, EventArgs e)
  675. {
  676. if (sender is DocumentWorkspace)
  677. {
  678. Bitmap bitmap = ((DocumentWorkspace)sender).CompositionSurface.CreateAliasedBitmap();
  679. foreach (Control C in this.panel2.Controls)
  680. {
  681. if (C is DepthExtensionPicTool)
  682. {
  683. DepthExtensionPicTool depthExtensionPicTool = (DepthExtensionPicTool)C;
  684. if (depthExtensionPicTool.pictureBox1.Image == null)
  685. {
  686. if (bitmap.Width > depthExtensionPicTool.pictureBox1.Size.Width || bitmap.Height > depthExtensionPicTool.pictureBox1.Size.Height)
  687. {
  688. depthExtensionPicTool.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
  689. }
  690. else
  691. {
  692. depthExtensionPicTool.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
  693. }
  694. depthExtensionPicTool.pictureBox1.Image = bitmap;
  695. depthExtensionPicTool.panel2.Visible = false;
  696. depthExtensionPicTool.panel1.Visible = true;
  697. //根据插入的控件位置修改滚动条
  698. Point oldScrollPoint = this.panel2.AutoScrollPosition;
  699. Point scrollPoint = new Point(depthExtensionPicTool.Location.X + Math.Abs(oldScrollPoint.X) + depthExtensionPicTool.Width - this.panel2.Width,
  700. depthExtensionPicTool.Location.Y + Math.Abs(oldScrollPoint.Y) + depthExtensionPicTool.Height - this.panel2.Height);
  701. if (this.panel2.HorizontalScroll.Visible)
  702. scrollPoint.X += 16;//固定滚动条尺寸,可能不是完全精准
  703. if (this.panel2.VerticalScroll.Visible)
  704. scrollPoint.Y += 16;//固定滚动条尺寸,可能不是完全精准
  705. this.panel2.AutoScrollPosition = scrollPoint;
  706. return;
  707. }
  708. }
  709. }
  710. }
  711. }
  712. /// <summary>
  713. /// 点击硬盘文件按钮
  714. /// </summary>
  715. /// <param name="sender"></param>
  716. /// <param name="e"></param>
  717. private void button7_Click(object sender, EventArgs e)
  718. {
  719. List<Bitmap> listBitmap = ChooseImagesFromHardDisk();
  720. if (listBitmap != null && listBitmap.Count > 0)
  721. {
  722. int addedImgNum = 0;
  723. for (int i = 0; i < listBitmap.Count; i++)
  724. {
  725. foreach (Control C in this.panel2.Controls)
  726. {
  727. if (C is DepthExtensionPicTool)
  728. {
  729. DepthExtensionPicTool depthExtensionPicTool = (DepthExtensionPicTool)C;
  730. if (depthExtensionPicTool.pictureBox1.Image == null)
  731. {
  732. if (listBitmap[i].Width > depthExtensionPicTool.pictureBox1.Size.Width || listBitmap[i].Height > depthExtensionPicTool.pictureBox1.Size.Height)
  733. {
  734. depthExtensionPicTool.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
  735. }
  736. else
  737. {
  738. depthExtensionPicTool.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
  739. }
  740. depthExtensionPicTool.pictureBox1.Image = listBitmap[i];
  741. depthExtensionPicTool.panel2.Visible = false;
  742. depthExtensionPicTool.panel1.Visible = true;
  743. addedImgNum++;
  744. //如果添加的是最后一张图,移动panel的滚动条到该控件位置
  745. if (addedImgNum == listBitmap.Count)
  746. {
  747. //根据插入的控件位置修改滚动条
  748. Point oldScrollPoint = this.panel2.AutoScrollPosition;
  749. Point scrollPoint = new Point(depthExtensionPicTool.Location.X + Math.Abs(oldScrollPoint.X) + depthExtensionPicTool.Width - this.panel2.Width,
  750. depthExtensionPicTool.Location.Y + Math.Abs(oldScrollPoint.Y) + depthExtensionPicTool.Height - this.panel2.Height);
  751. if (this.panel2.HorizontalScroll.Visible)
  752. scrollPoint.X += 16;
  753. if (this.panel2.VerticalScroll.Visible)
  754. scrollPoint.Y += 16;
  755. this.panel2.AutoScrollPosition = scrollPoint;
  756. }
  757. break;
  758. }
  759. }
  760. }
  761. }
  762. }
  763. }
  764. /// <summary>
  765. /// 从硬盘选择单张图片
  766. /// </summary>
  767. /// <returns></returns>
  768. private Bitmap ChooseImageFromHardDisk()
  769. {
  770. var openFileDialog = new OpenFileDialog { Filter = "*.jpg,*jpeg,*.bmp,*.ico,*.png,*.tif,*.wmf|*.jpg;*jpeg;*.bmp;*.ico;*.png;*.tif;*.wmf" };
  771. if (openFileDialog.ShowDialog() == DialogResult.OK)
  772. {
  773. Image image = Image.FromFile(openFileDialog.FileName);
  774. Bitmap newBit = new Bitmap(image);
  775. return newBit;
  776. }
  777. else
  778. {
  779. return null;
  780. }
  781. }
  782. /// <summary>
  783. /// 从硬盘选择多张图片
  784. /// </summary>
  785. /// <returns></returns>
  786. private List<Bitmap> ChooseImagesFromHardDisk()
  787. {
  788. var openFileDialog = new OpenFileDialog { Filter = "*.jpg,*jpeg,*.bmp,*.ico,*.png,*.tif,*.wmf|*.jpg;*jpeg;*.bmp;*.ico;*.png;*.tif;*.wmf" };
  789. openFileDialog.Multiselect = true;
  790. if (openFileDialog.ShowDialog() == DialogResult.OK)
  791. {
  792. string[] imageNames = openFileDialog.FileNames;
  793. List<Bitmap> listBitmap = new List<Bitmap>();
  794. foreach (string imgName in imageNames)
  795. {
  796. Image image = Image.FromFile(imgName);
  797. listBitmap.Add(new Bitmap(image));
  798. }
  799. return listBitmap;
  800. }
  801. else
  802. {
  803. return null;
  804. }
  805. }
  806. /// <summary>
  807. /// 第一步按钮
  808. /// </summary>
  809. /// <param name="sender"></param>
  810. /// <param name="e"></param>
  811. private void button1_Click(object sender, EventArgs e)
  812. {
  813. if (this.groupBox2.Visible && this.groupBox3.Visible)
  814. return;
  815. ChangeButtonStyle(this.button1, this.button2, this.button3);
  816. this.groupBoxStep2Operate.Visible = false;
  817. this.groupBox5.Visible = false;
  818. this.groupBox6.Visible = false;
  819. this.groupBox7.Visible = false;
  820. this.groupBox2.Visible = true;
  821. this.groupBox3.Visible = true;
  822. }
  823. /// <summary>
  824. /// 第二步按钮
  825. /// </summary>
  826. /// <param name="sender"></param>
  827. /// <param name="e"></param>
  828. private void button2_Click(object sender, EventArgs e)
  829. {
  830. if (this.groupBoxStep2Operate.Visible && this.groupBox5.Visible)
  831. return;
  832. ChangeButtonStyle(this.button2, this.button1, this.button3);
  833. this.groupBox2.Visible = false;
  834. this.groupBox3.Visible = false;
  835. this.groupBox6.Visible = false;
  836. this.groupBox7.Visible = false;
  837. this.groupBoxStep2Operate.Visible = true;
  838. this.groupBox5.Visible = true;
  839. }
  840. /// <summary>
  841. /// 初始化第二步的图片自定义控件
  842. /// </summary>
  843. private void ReloadStepTwoControls()
  844. {
  845. this.panel2.Controls.Clear();
  846. if (!string.IsNullOrEmpty(this.tbxColunmN.Text) && !string.IsNullOrEmpty(this.textBox2.Text))
  847. {
  848. int colNum = this.tbxColunmN.Text == "" ? 0 : Convert.ToInt32(this.tbxColunmN.Text);//列数
  849. int rowNum = this.textBox2.Text == "" ? 0 : Convert.ToInt32(this.textBox2.Text);//行数
  850. int toolsTagNum = 1;
  851. Point startPoint = new Point(0, 4);
  852. if (colNum < 5)
  853. startPoint.X = (this.panel1.Width - (116 * colNum)) / (colNum + 1);
  854. int marginTB = 7;//固定的上下边距
  855. for (int i = 0; i < rowNum; i++)
  856. {
  857. for (int j = 0; j < colNum; j++)
  858. {
  859. DepthExtensionPicTool depthExtensionPicTool = new DepthExtensionPicTool();
  860. depthExtensionPicTool.Tag = toolsTagNum;
  861. depthExtensionPicTool.Size = new Size(116, 116);
  862. if (colNum >= 5)
  863. depthExtensionPicTool.Location = new Point((120 * j), startPoint.Y + ((116 + marginTB) * i));
  864. else//水平数小于5时,边距是动态的
  865. depthExtensionPicTool.Location = new Point(startPoint.X + ((startPoint.X + 116) * j), startPoint.Y + ((116 + marginTB) * i));
  866. depthExtensionPicTool.panel1.Cursor = Cursors.Hand;
  867. depthExtensionPicTool.panel1.Paint += new PaintEventHandler(panelDel_Paint);
  868. depthExtensionPicTool.panel1.Click += new EventHandler(panelDel_Click);
  869. depthExtensionPicTool.panel2.Cursor = Cursors.Hand;
  870. depthExtensionPicTool.panel2.Paint += new PaintEventHandler(panelAdd_Paint);
  871. depthExtensionPicTool.panel2.Click += new EventHandler(panelAdd_Click);
  872. depthExtensionPicTool.pictureBox1.MouseDown += new MouseEventHandler(picTool_MouseDown);
  873. depthExtensionPicTool.pictureBox1.MouseMove += new MouseEventHandler(picTool_MouseMove);
  874. depthExtensionPicTool.pictureBox1.MouseUp += new MouseEventHandler(picTool_MouseUp);
  875. this.panel2.Controls.Add(depthExtensionPicTool);
  876. toolsTagNum++;
  877. if (colNum > 1)//只有一列不绘制"倒置"button
  878. {
  879. if (j == colNum - 1)
  880. {
  881. Button convertButton = new Button();
  882. convertButton.Name = "convertButton";
  883. convertButton.Text = PdnResources.GetString("Menu.ImageProcessing.Imagestitching.upside-down.text");
  884. convertButton.Tag = i + 1;
  885. convertButton.Size = new System.Drawing.Size(50, 23);
  886. if (colNum >= 5)
  887. convertButton.Location = new Point((120 * j) + 116 + 10, startPoint.Y + ((116 + marginTB) * i) + 47);
  888. else
  889. convertButton.Location = new Point(startPoint.X + ((startPoint.X + 116) * j) + 116 + 15, startPoint.Y + ((116 + marginTB) * i) + 47);
  890. convertButton.Click += new EventHandler(convertButton_Click);
  891. this.panel2.Controls.Add(convertButton);
  892. }
  893. }
  894. }
  895. }
  896. }
  897. }
  898. /// <summary>
  899. /// 图片自定义控件的鼠标按下事件
  900. /// </summary>
  901. /// <param name="sender"></param>
  902. /// <param name="e"></param>
  903. private void picTool_MouseDown(object sender, MouseEventArgs e)
  904. {
  905. if (e.Button == MouseButtons.Left)
  906. {
  907. isMouseDown = true;
  908. PictureBox pictureBox = (PictureBox)sender;
  909. ((DepthExtensionPicTool)pictureBox.Parent).Cursor = Cursors.SizeAll;
  910. picToolLocation = ((DepthExtensionPicTool)pictureBox.Parent).Location;
  911. oldToolLocation = ((DepthExtensionPicTool)pictureBox.Parent).Location;
  912. oldToolTag = Convert.ToInt32(((DepthExtensionPicTool)pictureBox.Parent).Tag);
  913. mouseOffset = Control.MousePosition;
  914. }
  915. }
  916. /// <summary>
  917. /// 图片自定义控件的鼠标抬起事件
  918. /// </summary>
  919. /// <param name="sender"></param>
  920. /// <param name="e"></param>
  921. private void picTool_MouseUp(object sender, MouseEventArgs e)
  922. {
  923. if (!isMouseDown) return;//双击选择图片后可能异常进入该事件,不做处理
  924. isMouseDown = false;
  925. PictureBox pictureBox = (PictureBox)sender;
  926. DepthExtensionPicTool depthExtensionPicTool = (DepthExtensionPicTool)pictureBox.Parent;
  927. List<DepthExtensionPicTool> listDepthExtensionPicTool = new List<DepthExtensionPicTool>();
  928. foreach (Control C in this.panel2.Controls)
  929. {
  930. if (C is DepthExtensionPicTool && (DepthExtensionPicTool)C != depthExtensionPicTool)
  931. {
  932. listDepthExtensionPicTool.Add((DepthExtensionPicTool)C);
  933. }
  934. }
  935. if (listDepthExtensionPicTool != null && listDepthExtensionPicTool.Count > 0)
  936. {
  937. for (int i = 0; i < listDepthExtensionPicTool.Count; i++)
  938. {
  939. Point toolScreenLocation = listDepthExtensionPicTool[i].Location;
  940. int toolTag = Convert.ToInt32(listDepthExtensionPicTool[i].Tag);
  941. Rectangle toolScreenRectangle = new Rectangle(toolScreenLocation.X, toolScreenLocation.Y, 116, 116);//获得自定义控件对应的矩形区域
  942. Point nowPoint = this.panel2.PointToClient(Control.MousePosition);//将屏幕鼠标点转换为控件坐标点
  943. if (toolScreenRectangle.Contains(nowPoint) && toolTag != oldToolTag)
  944. {
  945. //替换两个控件的location和tag
  946. depthExtensionPicTool.Location = toolScreenLocation;
  947. depthExtensionPicTool.Tag = toolTag;
  948. listDepthExtensionPicTool[i].Location = oldToolLocation;
  949. listDepthExtensionPicTool[i].Tag = oldToolTag;
  950. this.panel2.Refresh();
  951. return;
  952. }
  953. }
  954. }
  955. //如果鼠标点不与其他自定义控件重合,则当前拖动控件回到原始点
  956. depthExtensionPicTool.Location = oldToolLocation;
  957. }
  958. /// <summary>
  959. /// 图片自定义控件的鼠标拖动事件
  960. /// </summary>
  961. /// <param name="sender"></param>
  962. /// <param name="e"></param>
  963. private void picTool_MouseMove(object sender, MouseEventArgs e)
  964. {
  965. int _x = 0;
  966. int _y = 0;
  967. if (isMouseDown)
  968. {
  969. Point pt = Control.MousePosition;
  970. _x = mouseOffset.X - pt.X;
  971. _y = mouseOffset.Y - pt.Y;
  972. PictureBox pictureBox = (PictureBox)sender;
  973. ((DepthExtensionPicTool)pictureBox.Parent).Cursor = Cursors.SizeAll;
  974. ((DepthExtensionPicTool)pictureBox.Parent).Location = new Point(picToolLocation.X - _x, picToolLocation.Y - _y);
  975. }
  976. }
  977. /// <summary>
  978. /// 第三步按钮
  979. /// </summary>
  980. /// <param name="sender"></param>
  981. /// <param name="e"></param>
  982. private void button3_Click(object sender, EventArgs e)
  983. {
  984. if (this.groupBox6.Visible && this.groupBox7.Visible)
  985. return;
  986. ChangeButtonStyle(this.button3, this.button1, this.button2);
  987. this.groupBox2.Visible = false;
  988. this.groupBox3.Visible = false;
  989. this.groupBoxStep2Operate.Visible = false;
  990. this.groupBox5.Visible = false;
  991. this.groupBox6.Visible = true;
  992. this.groupBox7.Visible = true;
  993. this.textBox3.Text = PdnResources.GetString("Menu.Image.Text") + "-" + PdnResources.GetString("Menu.ImageCollection.ImageStitching.Text") + "-" + stepNumber;
  994. this.pictureBox1.Image = null;
  995. this._mosaicsImage = null;
  996. //获取第二步的所有图片
  997. List<Bitmap> bitmapList = new List<Bitmap>();
  998. List<int> tagList = new List<int>();
  999. foreach (Control C in this.panel2.Controls)
  1000. {
  1001. if (C is DepthExtensionPicTool)
  1002. {
  1003. DepthExtensionPicTool depthExtensionPicTool = (DepthExtensionPicTool)C;
  1004. if (depthExtensionPicTool.pictureBox1.Image != null)
  1005. {
  1006. bitmapList.Add((Bitmap)(depthExtensionPicTool.pictureBox1.Image));
  1007. tagList.Add((int)depthExtensionPicTool.Tag);
  1008. }
  1009. }
  1010. }
  1011. if (bitmapList.Count < 2)//少于两张图时不做处理
  1012. {
  1013. MessageBox.Show(PdnResources.GetString("Menu.Imporlessthatwopicturesunabletojoin.Text"));
  1014. return;
  1015. }
  1016. else
  1017. {
  1018. OpenCvSharp.Mat[] mats = new OpenCvSharp.Mat[bitmapList.Count];
  1019. int index = 0;
  1020. foreach (Bitmap bitmap in bitmapList)
  1021. {
  1022. var i = tagList[index] - 1;
  1023. mats[index] = PaintDotNet.Camera.Tools.ToMat(bitmapList[index]);
  1024. index++;
  1025. }
  1026. ////进行图片拼接
  1027. Boolean errorFlag = false;
  1028. //OpenCvSharp.Mat mat = AdjustIntent.MatchPicByXFeatures2D(mats, out errorFlag);
  1029. int colNum = this.tbxColunmN.Text == "" ? 0 : Convert.ToInt32(this.tbxColunmN.Text);//列数
  1030. double rate = (double)numOverlapRate.Value;
  1031. OpenCvSharp.Mat mat = AdjustIntent.MatchPicOneByOne2D(mats, colNum, rate, out errorFlag/*, false*/);
  1032. if (errorFlag || mat.Width < 1 || mat.Height < 1)//宽高大于0代表拼接成功,只能操作可拼接的图片
  1033. {
  1034. MessageBox.Show(PdnResources.GetString("Menu.ImageMosaicfailed.Text"));
  1035. return;
  1036. }
  1037. _mosaicsImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat);
  1038. if (_mosaicsImage != null)
  1039. {
  1040. if (_mosaicsImage.Width > this.pictureBox1.Size.Width || _mosaicsImage.Height > this.pictureBox1.Size.Height)
  1041. {
  1042. this.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
  1043. }
  1044. else
  1045. {
  1046. this.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
  1047. }
  1048. this.pictureBox1.Image = _mosaicsImage;
  1049. }
  1050. }
  1051. _lastPoint = new Point(0, 0);
  1052. _isFirst = true;
  1053. }
  1054. /// <summary>
  1055. /// 修改第X步的按钮样式
  1056. /// </summary>
  1057. /// <param name="displayButton">要修改的按钮</param>
  1058. /// <param name="hideButton1">要恢复的按钮1</param>
  1059. /// <param name="hideButton2">要恢复的按钮2</param>
  1060. private void ChangeButtonStyle(Button displayButton, Button hideButton1, Button hideButton2)
  1061. {
  1062. hideButton1.BackColor = Color.FromArgb(255, 240, 240, 240);
  1063. hideButton1.ForeColor = Color.FromArgb(255, 0, 0, 0);
  1064. hideButton1.FlatStyle = FlatStyle.Standard;
  1065. hideButton1.FlatAppearance.BorderSize = 1;
  1066. hideButton2.BackColor = Color.FromArgb(255, 240, 240, 240);
  1067. hideButton2.ForeColor = Color.FromArgb(255, 0, 0, 0);
  1068. hideButton2.FlatStyle = FlatStyle.Standard;
  1069. hideButton2.FlatAppearance.BorderSize = 1;
  1070. displayButton.BackColor = Color.Gray;
  1071. displayButton.ForeColor = Color.White;
  1072. displayButton.FlatStyle = FlatStyle.Flat;
  1073. displayButton.FlatAppearance.BorderSize = 0;
  1074. }
  1075. /// <summary>
  1076. /// 绘制删除图标
  1077. /// </summary>
  1078. /// <param name="sender"></param>
  1079. /// <param name="e"></param>
  1080. private void panelDel_Paint(object sender, PaintEventArgs e)
  1081. {
  1082. Image deleteImg = PdnResources.GetImageResource("Images.ImageStrip.CloseButton.Hot.png").Reference;//从项目中随便找了一个红色的删除图片
  1083. if (deleteImg != null)
  1084. {
  1085. Graphics g = e.Graphics;
  1086. g.DrawImage(deleteImg, 0, 0);
  1087. }
  1088. }
  1089. /// <summary>
  1090. /// 绘制添加功能的十字线
  1091. /// </summary>
  1092. /// <param name="sender"></param>
  1093. /// <param name="e"></param>
  1094. private void panelAdd_Paint(object sender, PaintEventArgs e)
  1095. {
  1096. Panel panel = (Panel)sender;
  1097. Size panelSize = panel.Size;
  1098. Graphics g = e.Graphics;
  1099. Pen linePen = new Pen(Color.Black);
  1100. linePen.Width = 3;
  1101. g.DrawLine(linePen, new Point(0, panelSize.Height / 2), new Point(panelSize.Width, panelSize.Height / 2));
  1102. g.DrawLine(linePen, new Point(panelSize.Width / 2, 0), new Point(panelSize.Width / 2, panelSize.Height));
  1103. linePen.Dispose();
  1104. }
  1105. /// <summary>
  1106. /// 点击添加标志
  1107. /// </summary>
  1108. /// <param name="sender"></param>
  1109. /// <param name="e"></param>
  1110. private void panelAdd_Click(object sender, EventArgs e)
  1111. {
  1112. Bitmap bitmap = ChooseImageFromHardDisk();
  1113. if (bitmap != null)
  1114. {
  1115. Panel panel = (Panel)sender;
  1116. DepthExtensionPicTool parentTool = (DepthExtensionPicTool)panel.Parent;
  1117. if (bitmap.Width > parentTool.pictureBox1.Size.Width || bitmap.Height > parentTool.pictureBox1.Size.Height)
  1118. {
  1119. parentTool.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
  1120. }
  1121. else
  1122. {
  1123. parentTool.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
  1124. }
  1125. parentTool.pictureBox1.Image = bitmap;
  1126. parentTool.panel2.Visible = false;
  1127. parentTool.panel1.Visible = true;
  1128. }
  1129. }
  1130. /// <summary>
  1131. /// 点击删除图标
  1132. /// </summary>
  1133. /// <param name="sender"></param>
  1134. /// <param name="e"></param>
  1135. private void panelDel_Click(object sender, EventArgs e)
  1136. {
  1137. Panel panel = (Panel)sender;
  1138. DepthExtensionPicTool parentTool = (DepthExtensionPicTool)panel.Parent;
  1139. if (parentTool.pictureBox1.Image != null)
  1140. {
  1141. parentTool.pictureBox1.Image = null;
  1142. parentTool.panel2.Visible = true;
  1143. parentTool.panel1.Visible = false;
  1144. }
  1145. }
  1146. /// <summary>
  1147. /// 点击倒置按钮
  1148. /// </summary>
  1149. /// <param name="sender"></param>
  1150. /// <param name="e"></param>
  1151. private void convertButton_Click(object sender, EventArgs e)
  1152. {
  1153. Button convertBtn = (Button)sender;
  1154. int rowNum = 0;
  1155. if (convertBtn.Tag != null && convertBtn.Tag.ToString().Length > 0)
  1156. {
  1157. rowNum = Convert.ToInt32(convertBtn.Tag.ToString());//button的tag值确定是第几行
  1158. }
  1159. if (rowNum > 0)
  1160. {
  1161. int colNum = this.tbxColunmN.Text == "" ? 0 : Convert.ToInt32(this.tbxColunmN.Text);//列数
  1162. //取得点击按钮所在行的图片自定义控件tag的最大值与最小值
  1163. int minTag = colNum * (rowNum - 1) + 1;
  1164. int maxTag = colNum * rowNum;
  1165. //取得所有图片自定义控件的list
  1166. List<DepthExtensionPicTool> picToolList = new List<DepthExtensionPicTool>();
  1167. foreach (Control C in this.panel2.Controls)
  1168. {
  1169. if (C is DepthExtensionPicTool)
  1170. {
  1171. picToolList.Add((DepthExtensionPicTool)C);
  1172. }
  1173. }
  1174. //取得tag值所对应的图片自定义控件对象
  1175. List<DepthExtensionPicTool> convertPicToolList = picToolList.FindAll(a => Convert.ToInt32(a.Tag) >= minTag && Convert.ToInt32(a.Tag) <= maxTag);
  1176. convertPicToolList = convertPicToolList.OrderBy(a => a.Location.X).ToList();//按location重新排序
  1177. List<Point> locationPoint = new List<Point>(convertPicToolList.Select(a => a.Location).ToList());//取得这些对象的location
  1178. //反转后再重新赋回去
  1179. locationPoint.Reverse();
  1180. for (int j = 0; j < convertPicToolList.Count; j++)
  1181. {
  1182. convertPicToolList[j].Location = locationPoint[j];
  1183. }
  1184. for (int j = 0; j < convertPicToolList.Count / 2; j++)
  1185. {
  1186. int tag1 = (int)convertPicToolList[j].Tag;
  1187. convertPicToolList[j].Tag = (int)convertPicToolList[convertPicToolList.Count - j - 1].Tag;
  1188. convertPicToolList[convertPicToolList.Count - j - 1].Tag = tag1;
  1189. }
  1190. }
  1191. }
  1192. /// <summary>
  1193. /// 保存按钮
  1194. /// </summary>
  1195. /// <param name="sender"></param>
  1196. /// <param name="e"></param>
  1197. private void button8_Click(object sender, EventArgs e)
  1198. {
  1199. if (this.pictureBox1.Image != null && _mosaicsImage != null)
  1200. {
  1201. double widthRatio = imageRect.Width / (_mosaicsImage.Width * 1d);//缩略图与原图的宽度比
  1202. double heightRatio = imageRect.Height / (_mosaicsImage.Height * 1d);//缩略图与原图的高度比
  1203. int xc = (this.pictureBox1.Width - this.imageRect.Width) / 2;//缩略图横坐标与控件原点的偏移量
  1204. int yc = (this.pictureBox1.Height - this.imageRect.Height) / 2;//缩略图纵坐标与控件原点的偏移量
  1205. int cutX = Convert.ToInt32((zoomRect.X - xc) / widthRatio);
  1206. int cutY = Convert.ToInt32((zoomRect.Y - yc) / heightRatio);
  1207. int cutWidth = Convert.ToInt32(zoomRect.Width / widthRatio);
  1208. int cutHeight = Convert.ToInt32(zoomRect.Height / heightRatio);
  1209. Bitmap cutBitmap = DrawRulerHelper.KiCut(new Bitmap(this.pictureBox1.Image), cutX, cutY, cutWidth, cutHeight);
  1210. if (cutBitmap != null)
  1211. {
  1212. DocumentWorkspace dw = appWorkspace.AddNewDocumentWorkspace();
  1213. Document document = Document.FromImageMat(Camera.Tools.ToMat(cutBitmap));
  1214. dw.Document = document;
  1215. dw.xmlSaveModel = Startup.instance.ruleDB;
  1216. dw.InitRulerInfo();
  1217. dw.fileText = this.textBox3.Text;
  1218. appWorkspace.ActiveDocumentWorkspace = dw;
  1219. Startup.instance.step_length += 1;
  1220. stepNumber = "00" + Startup.instance.step_length;
  1221. this.textBox3.Text = PdnResources.GetString("Menu.Image.Text") + "-" + PdnResources.GetString("Menu.ImageCollection.ImageStitching.Text") + "-" + stepNumber;
  1222. }
  1223. }
  1224. }
  1225. /// <summary>
  1226. /// 绘制picturebox中的矩形框
  1227. /// </summary>
  1228. /// <param name="sender"></param>
  1229. /// <param name="e"></param>
  1230. private void pictureBox1_Paint(object sender, PaintEventArgs e)
  1231. {
  1232. if (this.pictureBox1.Image != null)
  1233. {
  1234. Pen rectPen = new Pen(Color.LightGreen);
  1235. rectPen.Width = 3;
  1236. if (_isFirst)
  1237. {
  1238. //获取缩略图对应矩形
  1239. PropertyInfo _ImageRectanglePropert = this.pictureBox1.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic);
  1240. imageRect = (Rectangle)_ImageRectanglePropert.GetValue(this.pictureBox1, null);
  1241. zoomRect = new Rectangle(imageRect.X, imageRect.Y, imageRect.Width, imageRect.Height);
  1242. }
  1243. e.Graphics.DrawRectangle(rectPen, zoomRect.X, zoomRect.Y, zoomRect.Width - 1, zoomRect.Height - 1);
  1244. e.Graphics.FillRectangle(new SolidBrush(Color.Black), new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 7, 7));
  1245. rectPen.Dispose();
  1246. }
  1247. }
  1248. /// <summary>
  1249. /// 矩形框的选中
  1250. /// </summary>
  1251. /// <param name="sender"></param>
  1252. /// <param name="e"></param>
  1253. private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
  1254. {
  1255. _lastPoint.X = e.X;
  1256. _lastPoint.Y = e.Y;
  1257. //是否平移
  1258. if (zoomRect.Contains(e.Location) && !new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 7, 7).Contains(e.Location))
  1259. isMoved = true;
  1260. else
  1261. isMoved = false;
  1262. //是否调整大小
  1263. if (new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 7, 7).Contains(e.Location))
  1264. isResized = true;
  1265. else
  1266. isResized = false;
  1267. }
  1268. /// <summary>
  1269. /// 矩形框的拖动和改变大小
  1270. /// </summary>
  1271. /// <param name="sender"></param>
  1272. /// <param name="e"></param>
  1273. private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
  1274. {
  1275. //修改鼠标形状
  1276. this.pictureBox1.Cursor = Cursors.Default;
  1277. if (zoomRect != null)
  1278. {
  1279. if (zoomRect.Contains(e.Location) && !new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 7, 7).Contains(e.Location))
  1280. {
  1281. this.pictureBox1.Cursor = Cursors.SizeAll;
  1282. }
  1283. if (new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 7, 7).Contains(e.Location))
  1284. {
  1285. this.pictureBox1.Cursor = Cursors.SizeNWSE;
  1286. }
  1287. }
  1288. if (e.Button != MouseButtons.Left)
  1289. return;
  1290. //拖拽
  1291. if (zoomRect != null && isMoved)
  1292. {
  1293. _isFirst = false;
  1294. Point p = e.Location;
  1295. int dx = p.X - _lastPoint.X;
  1296. int dy = p.Y - _lastPoint.Y;
  1297. _lastPoint.X = p.X;
  1298. _lastPoint.Y = p.Y;
  1299. zoomRect.X += dx;
  1300. zoomRect.Y += dy;
  1301. //控制矩形框不超过缩略图尺寸
  1302. int xc = (this.pictureBox1.Width - this.imageRect.Width) / 2;
  1303. int yc = (this.pictureBox1.Height - this.imageRect.Height) / 2;
  1304. if (zoomRect.X < xc) zoomRect.X = xc;
  1305. if (zoomRect.Y < yc) zoomRect.Y = yc;
  1306. if (zoomRect.X + zoomRect.Width > imageRect.Width + xc) zoomRect.X = imageRect.Width - zoomRect.Width + xc;
  1307. if (zoomRect.Y + zoomRect.Height > imageRect.Height + yc) zoomRect.Y = imageRect.Height - zoomRect.Height + yc;
  1308. this.pictureBox1.Refresh();
  1309. }
  1310. //调整大小
  1311. if (zoomRect != null && isResized)
  1312. {
  1313. _isFirst = false;
  1314. Point p = e.Location;
  1315. //不允许超出矩形框的原点
  1316. if (p.X < zoomRect.X + 5)
  1317. {
  1318. p.X = zoomRect.X + 5;
  1319. }
  1320. if (p.Y < zoomRect.Y + 5)
  1321. {
  1322. p.Y = zoomRect.Y + 5;
  1323. }
  1324. //修改矩形框尺寸
  1325. int top = zoomRect.Top;
  1326. int left = zoomRect.Left;
  1327. int right = zoomRect.Right;
  1328. int bottom = zoomRect.Bottom;
  1329. right = p.X;
  1330. bottom = p.Y;
  1331. zoomRect = new Rectangle(left, top, right - left, bottom - top);
  1332. //控制矩形框不超过缩略图尺寸
  1333. int xc = (this.pictureBox1.Width - this.imageRect.Width) / 2;
  1334. int yc = (this.pictureBox1.Height - this.imageRect.Height) / 2;
  1335. if (zoomRect.X < xc) zoomRect.X = xc;
  1336. if (zoomRect.Y < yc) zoomRect.Y = yc;
  1337. if (zoomRect.X + zoomRect.Width > imageRect.Width + xc) zoomRect.Width = imageRect.Width + xc - zoomRect.X;
  1338. if (zoomRect.Y + zoomRect.Height > imageRect.Height + yc) zoomRect.Height = imageRect.Height + yc - zoomRect.Y;
  1339. this.pictureBox1.Refresh();
  1340. }
  1341. }
  1342. /// <summary>
  1343. /// 返回按钮
  1344. /// </summary>
  1345. /// <param name="sender"></param>
  1346. /// <param name="e"></param>
  1347. private void button5_Click(object sender, EventArgs e)
  1348. {
  1349. //第二步
  1350. if (this.groupBox6.Visible && this.groupBox7.Visible)
  1351. {
  1352. this.button2.PerformClick();
  1353. return;
  1354. }
  1355. //第一步
  1356. if (this.groupBoxStep2Operate.Visible && this.groupBox5.Visible)
  1357. {
  1358. this.button1.PerformClick();
  1359. return;
  1360. }
  1361. }
  1362. /// <summary>
  1363. /// 下一步按钮
  1364. /// </summary>
  1365. /// <param name="sender"></param>
  1366. /// <param name="e"></param>
  1367. private void button4_Click(object sender, EventArgs e)
  1368. {
  1369. //第二步
  1370. if (this.groupBox2.Visible && this.groupBox3.Visible)
  1371. {
  1372. this.button2.PerformClick();
  1373. return;
  1374. }
  1375. //第三步
  1376. if (this.groupBoxStep2Operate.Visible && this.groupBox5.Visible)
  1377. {
  1378. this.button3.PerformClick();
  1379. return;
  1380. }
  1381. }
  1382. }
  1383. }