ImageMosaicsDialog.cs 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458
  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.groupBoxStep2Operate);
  455. this.Controls.Add(this.groupBox3);
  456. this.Controls.Add(this.groupBox2);
  457. this.Controls.Add(this.groupBox1);
  458. this.Controls.Add(this.groupBox6);
  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.groupBox6, 0);
  465. this.Controls.SetChildIndex(this.groupBox1, 0);
  466. this.Controls.SetChildIndex(this.groupBox2, 0);
  467. this.Controls.SetChildIndex(this.groupBox3, 0);
  468. this.Controls.SetChildIndex(this.groupBoxStep2Operate, 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. /// 限制只可以输入0-9数字以及退格键
  544. /// </summary>
  545. /// <param name="sender"></param>
  546. /// <param name="e"></param>
  547. private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
  548. {
  549. if (e.KeyChar != '\b')//这是允许输入退格键 
  550.             {
  551. int len = this.tbxColunmN.Text.Length;
  552. if (len < 1 && e.KeyChar == '0')
  553. {
  554. e.Handled = true;
  555. }
  556. else if ((e.KeyChar < '0') || (e.KeyChar > '9'))//这是允许输入0-9数字 
  557.                 {
  558. e.Handled = true;
  559. }
  560. }
  561. }
  562. /// <summary>
  563. /// 限制只可以输入0-9数字以及退格键
  564. /// </summary>
  565. /// <param name="sender"></param>
  566. /// <param name="e"></param>
  567. private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
  568. {
  569. if (e.KeyChar != '\b')//这是允许输入退格键 
  570.             {
  571. int len = this.textBox2.Text.Length;
  572. if (len < 1 && e.KeyChar == '0')
  573. {
  574. e.Handled = true;
  575. }
  576. else if ((e.KeyChar < '0') || (e.KeyChar > '9'))//这是允许输入0-9数字 
  577.                 {
  578. e.Handled = true;
  579. }
  580. }
  581. }
  582. /// <summary>
  583. /// 修改水平个数刷新panel
  584. /// </summary>
  585. /// <param name="sender"></param>
  586. /// <param name="e"></param>
  587. private void textBox1_TextChanged(object sender, EventArgs e)
  588. {
  589. this.panel1.Controls.Clear();
  590. AddPitureboxTools();
  591. ReloadStepTwoControls();
  592. }
  593. /// <summary>
  594. /// 修改垂直个数刷新panel
  595. /// </summary>
  596. /// <param name="sender"></param>
  597. /// <param name="e"></param>
  598. private void textBox2_TextChanged(object sender, EventArgs e)
  599. {
  600. this.panel1.Controls.Clear();
  601. AddPitureboxTools();
  602. ReloadStepTwoControls();
  603. }
  604. /// <summary>
  605. /// 点击当前软件按钮
  606. /// </summary>
  607. /// <param name="sender"></param>
  608. /// <param name="e"></param>
  609. private void button6_Click(object sender, EventArgs e)
  610. {
  611. if (imagePickerDialog == null)
  612. {
  613. imagePickerDialog = new InterImagePickerDialog(this.appWorkspace);
  614. imagePickerDialog.StartPosition = FormStartPosition.Manual;
  615. imagePickerDialog.Left = ((Button)sender).Left + 12 + this.Left;
  616. imagePickerDialog.Top = ((Button)sender).Bottom + 36 + this.Top;
  617. imagePickerDialog.ValueChanged += new System.EventHandler(this.inputMat_ValueChanged);
  618. imagePickerDialog.Show();
  619. }
  620. else
  621. {
  622. if (!imagePickerDialog.IsDisposed)
  623. {
  624. imagePickerDialog.WindowState = FormWindowState.Normal;
  625. }
  626. else
  627. {
  628. imagePickerDialog = new InterImagePickerDialog(this.appWorkspace);
  629. imagePickerDialog.StartPosition = FormStartPosition.Manual;
  630. imagePickerDialog.Left = ((Button)sender).Left + 12 + this.Left;
  631. imagePickerDialog.Top = ((Button)sender).Bottom + 36 + this.Top;
  632. imagePickerDialog.ValueChanged += new System.EventHandler(this.inputMat_ValueChanged);
  633. imagePickerDialog.Show();
  634. }
  635. }
  636. }
  637. /// <summary>
  638. /// 从图库选择待对照图片
  639. /// </summary>
  640. /// <param name="sender"></param>
  641. /// <param name="e"></param>
  642. private void inputMat_ValueChanged(object sender, EventArgs e)
  643. {
  644. if (sender is DocumentWorkspace)
  645. {
  646. Bitmap bitmap = ((DocumentWorkspace)sender).CompositionSurface.CreateAliasedBitmap();
  647. foreach (Control C in this.panel2.Controls)
  648. {
  649. if (C is DepthExtensionPicTool)
  650. {
  651. DepthExtensionPicTool depthExtensionPicTool = (DepthExtensionPicTool)C;
  652. if (depthExtensionPicTool.pictureBox1.Image == null)
  653. {
  654. if (bitmap.Width > depthExtensionPicTool.pictureBox1.Size.Width || bitmap.Height > depthExtensionPicTool.pictureBox1.Size.Height)
  655. {
  656. depthExtensionPicTool.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
  657. }
  658. else
  659. {
  660. depthExtensionPicTool.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
  661. }
  662. depthExtensionPicTool.pictureBox1.Image = bitmap;
  663. depthExtensionPicTool.panel2.Visible = false;
  664. depthExtensionPicTool.panel1.Visible = true;
  665. //根据插入的控件位置修改滚动条
  666. Point oldScrollPoint = this.panel2.AutoScrollPosition;
  667. Point scrollPoint = new Point(depthExtensionPicTool.Location.X + Math.Abs(oldScrollPoint.X) + depthExtensionPicTool.Width - this.panel2.Width,
  668. depthExtensionPicTool.Location.Y + Math.Abs(oldScrollPoint.Y) + depthExtensionPicTool.Height - this.panel2.Height);
  669. if (this.panel2.HorizontalScroll.Visible)
  670. scrollPoint.X += 16;//固定滚动条尺寸,可能不是完全精准
  671. if (this.panel2.VerticalScroll.Visible)
  672. scrollPoint.Y += 16;//固定滚动条尺寸,可能不是完全精准
  673. this.panel2.AutoScrollPosition = scrollPoint;
  674. return;
  675. }
  676. }
  677. }
  678. }
  679. }
  680. /// <summary>
  681. /// 点击硬盘文件按钮
  682. /// </summary>
  683. /// <param name="sender"></param>
  684. /// <param name="e"></param>
  685. private void button7_Click(object sender, EventArgs e)
  686. {
  687. List<Bitmap> listBitmap = ChooseImagesFromHardDisk();
  688. if (listBitmap != null && listBitmap.Count > 0)
  689. {
  690. int addedImgNum = 0;
  691. for (int i = 0; i < listBitmap.Count; i++)
  692. {
  693. foreach (Control C in this.panel2.Controls)
  694. {
  695. if (C is DepthExtensionPicTool)
  696. {
  697. DepthExtensionPicTool depthExtensionPicTool = (DepthExtensionPicTool)C;
  698. if (depthExtensionPicTool.pictureBox1.Image == null)
  699. {
  700. if (listBitmap[i].Width > depthExtensionPicTool.pictureBox1.Size.Width || listBitmap[i].Height > depthExtensionPicTool.pictureBox1.Size.Height)
  701. {
  702. depthExtensionPicTool.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
  703. }
  704. else
  705. {
  706. depthExtensionPicTool.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
  707. }
  708. depthExtensionPicTool.pictureBox1.Image = listBitmap[i];
  709. depthExtensionPicTool.panel2.Visible = false;
  710. depthExtensionPicTool.panel1.Visible = true;
  711. addedImgNum++;
  712. //如果添加的是最后一张图,移动panel的滚动条到该控件位置
  713. if (addedImgNum == listBitmap.Count)
  714. {
  715. //根据插入的控件位置修改滚动条
  716. Point oldScrollPoint = this.panel2.AutoScrollPosition;
  717. Point scrollPoint = new Point(depthExtensionPicTool.Location.X + Math.Abs(oldScrollPoint.X) + depthExtensionPicTool.Width - this.panel2.Width,
  718. depthExtensionPicTool.Location.Y + Math.Abs(oldScrollPoint.Y) + depthExtensionPicTool.Height - this.panel2.Height);
  719. if (this.panel2.HorizontalScroll.Visible)
  720. scrollPoint.X += 16;
  721. if (this.panel2.VerticalScroll.Visible)
  722. scrollPoint.Y += 16;
  723. this.panel2.AutoScrollPosition = scrollPoint;
  724. }
  725. break;
  726. }
  727. }
  728. }
  729. }
  730. }
  731. }
  732. /// <summary>
  733. /// 从硬盘选择单张图片
  734. /// </summary>
  735. /// <returns></returns>
  736. private Bitmap ChooseImageFromHardDisk()
  737. {
  738. var openFileDialog = new OpenFileDialog { Filter = "*.jpg,*jpeg,*.bmp,*.ico,*.png,*.tif,*.wmf|*.jpg;*jpeg;*.bmp;*.ico;*.png;*.tif;*.wmf" };
  739. if (openFileDialog.ShowDialog() == DialogResult.OK)
  740. {
  741. Image image = Image.FromFile(openFileDialog.FileName);
  742. Bitmap newBit = new Bitmap(image);
  743. return newBit;
  744. }
  745. else
  746. {
  747. return null;
  748. }
  749. }
  750. /// <summary>
  751. /// 从硬盘选择多张图片
  752. /// </summary>
  753. /// <returns></returns>
  754. private List<Bitmap> ChooseImagesFromHardDisk()
  755. {
  756. var openFileDialog = new OpenFileDialog { Filter = "*.jpg,*jpeg,*.bmp,*.ico,*.png,*.tif,*.wmf|*.jpg;*jpeg;*.bmp;*.ico;*.png;*.tif;*.wmf" };
  757. openFileDialog.Multiselect = true;
  758. if (openFileDialog.ShowDialog() == DialogResult.OK)
  759. {
  760. string[] imageNames = openFileDialog.FileNames;
  761. List<Bitmap> listBitmap = new List<Bitmap>();
  762. foreach (string imgName in imageNames)
  763. {
  764. Image image = Image.FromFile(imgName);
  765. listBitmap.Add(new Bitmap(image));
  766. }
  767. return listBitmap;
  768. }
  769. else
  770. {
  771. return null;
  772. }
  773. }
  774. /// <summary>
  775. /// 第一步按钮
  776. /// </summary>
  777. /// <param name="sender"></param>
  778. /// <param name="e"></param>
  779. private void button1_Click(object sender, EventArgs e)
  780. {
  781. if (this.groupBox2.Visible && this.groupBox3.Visible)
  782. return;
  783. ChangeButtonStyle(this.button1, this.button2, this.button3);
  784. this.groupBoxStep2Operate.Visible = false;
  785. this.groupBox5.Visible = false;
  786. this.groupBox6.Visible = false;
  787. this.groupBox7.Visible = false;
  788. this.groupBox2.Visible = true;
  789. this.groupBox3.Visible = true;
  790. }
  791. /// <summary>
  792. /// 第二步按钮
  793. /// </summary>
  794. /// <param name="sender"></param>
  795. /// <param name="e"></param>
  796. private void button2_Click(object sender, EventArgs e)
  797. {
  798. if (this.groupBoxStep2Operate.Visible && this.groupBox5.Visible)
  799. return;
  800. ChangeButtonStyle(this.button2, this.button1, this.button3);
  801. this.groupBox2.Visible = false;
  802. this.groupBox3.Visible = false;
  803. this.groupBox6.Visible = false;
  804. this.groupBox7.Visible = false;
  805. this.groupBoxStep2Operate.Visible = true;
  806. this.groupBox5.Visible = true;
  807. }
  808. /// <summary>
  809. /// 初始化第二步的图片自定义控件
  810. /// </summary>
  811. private void ReloadStepTwoControls()
  812. {
  813. this.panel2.Controls.Clear();
  814. if (!string.IsNullOrEmpty(this.tbxColunmN.Text) && !string.IsNullOrEmpty(this.textBox2.Text))
  815. {
  816. int colNum = this.tbxColunmN.Text == "" ? 0 : Convert.ToInt32(this.tbxColunmN.Text);//列数
  817. int rowNum = this.textBox2.Text == "" ? 0 : Convert.ToInt32(this.textBox2.Text);//行数
  818. int toolsTagNum = 1;
  819. Point startPoint = new Point(0, 4);
  820. if (colNum < 5)
  821. startPoint.X = (this.panel1.Width - (116 * colNum)) / (colNum + 1);
  822. int marginTB = 7;//固定的上下边距
  823. for (int i = 0; i < rowNum; i++)
  824. {
  825. for (int j = 0; j < colNum; j++)
  826. {
  827. DepthExtensionPicTool depthExtensionPicTool = new DepthExtensionPicTool();
  828. depthExtensionPicTool.Tag = toolsTagNum;
  829. depthExtensionPicTool.Size = new Size(116, 116);
  830. if (colNum >= 5)
  831. depthExtensionPicTool.Location = new Point((120 * j), startPoint.Y + ((116 + marginTB) * i));
  832. else//水平数小于5时,边距是动态的
  833. depthExtensionPicTool.Location = new Point(startPoint.X + ((startPoint.X + 116) * j), startPoint.Y + ((116 + marginTB) * i));
  834. depthExtensionPicTool.panel1.Cursor = Cursors.Hand;
  835. depthExtensionPicTool.panel1.Paint += new PaintEventHandler(panelDel_Paint);
  836. depthExtensionPicTool.panel1.Click += new EventHandler(panelDel_Click);
  837. depthExtensionPicTool.panel2.Cursor = Cursors.Hand;
  838. depthExtensionPicTool.panel2.Paint += new PaintEventHandler(panelAdd_Paint);
  839. depthExtensionPicTool.panel2.Click += new EventHandler(panelAdd_Click);
  840. depthExtensionPicTool.pictureBox1.MouseDown += new MouseEventHandler(picTool_MouseDown);
  841. depthExtensionPicTool.pictureBox1.MouseMove += new MouseEventHandler(picTool_MouseMove);
  842. depthExtensionPicTool.pictureBox1.MouseUp += new MouseEventHandler(picTool_MouseUp);
  843. this.panel2.Controls.Add(depthExtensionPicTool);
  844. toolsTagNum++;
  845. if (colNum > 1)//只有一列不绘制"倒置"button
  846. {
  847. if (j == colNum - 1)
  848. {
  849. Button convertButton = new Button();
  850. convertButton.Name = "convertButton";
  851. convertButton.Text = PdnResources.GetString("Menu.ImageProcessing.Imagestitching.upside-down.text");
  852. convertButton.Tag = i + 1;
  853. convertButton.Size = new System.Drawing.Size(50, 23);
  854. if (colNum >= 5)
  855. convertButton.Location = new Point((120 * j) + 116 + 10, startPoint.Y + ((116 + marginTB) * i) + 47);
  856. else
  857. convertButton.Location = new Point(startPoint.X + ((startPoint.X + 116) * j) + 116 + 15, startPoint.Y + ((116 + marginTB) * i) + 47);
  858. convertButton.Click += new EventHandler(convertButton_Click);
  859. this.panel2.Controls.Add(convertButton);
  860. }
  861. }
  862. }
  863. }
  864. }
  865. }
  866. /// <summary>
  867. /// 图片自定义控件的鼠标按下事件
  868. /// </summary>
  869. /// <param name="sender"></param>
  870. /// <param name="e"></param>
  871. private void picTool_MouseDown(object sender, MouseEventArgs e)
  872. {
  873. if (e.Button == MouseButtons.Left)
  874. {
  875. isMouseDown = true;
  876. PictureBox pictureBox = (PictureBox)sender;
  877. ((DepthExtensionPicTool)pictureBox.Parent).Cursor = Cursors.SizeAll;
  878. picToolLocation = ((DepthExtensionPicTool)pictureBox.Parent).Location;
  879. oldToolLocation = ((DepthExtensionPicTool)pictureBox.Parent).Location;
  880. oldToolTag = Convert.ToInt32(((DepthExtensionPicTool)pictureBox.Parent).Tag);
  881. mouseOffset = Control.MousePosition;
  882. }
  883. }
  884. /// <summary>
  885. /// 图片自定义控件的鼠标抬起事件
  886. /// </summary>
  887. /// <param name="sender"></param>
  888. /// <param name="e"></param>
  889. private void picTool_MouseUp(object sender, MouseEventArgs e)
  890. {
  891. if (!isMouseDown) return;//双击选择图片后可能异常进入该事件,不做处理
  892. isMouseDown = false;
  893. PictureBox pictureBox = (PictureBox)sender;
  894. DepthExtensionPicTool depthExtensionPicTool = (DepthExtensionPicTool)pictureBox.Parent;
  895. List<DepthExtensionPicTool> listDepthExtensionPicTool = new List<DepthExtensionPicTool>();
  896. foreach (Control C in this.panel2.Controls)
  897. {
  898. if (C is DepthExtensionPicTool && (DepthExtensionPicTool)C != depthExtensionPicTool)
  899. {
  900. listDepthExtensionPicTool.Add((DepthExtensionPicTool)C);
  901. }
  902. }
  903. if (listDepthExtensionPicTool != null && listDepthExtensionPicTool.Count > 0)
  904. {
  905. for (int i = 0; i < listDepthExtensionPicTool.Count; i++)
  906. {
  907. Point toolScreenLocation = listDepthExtensionPicTool[i].Location;
  908. int toolTag = Convert.ToInt32(listDepthExtensionPicTool[i].Tag);
  909. Rectangle toolScreenRectangle = new Rectangle(toolScreenLocation.X, toolScreenLocation.Y, 116, 116);//获得自定义控件对应的矩形区域
  910. Point nowPoint = this.panel2.PointToClient(Control.MousePosition);//将屏幕鼠标点转换为控件坐标点
  911. if (toolScreenRectangle.Contains(nowPoint) && toolTag != oldToolTag)
  912. {
  913. //替换两个控件的location和tag
  914. depthExtensionPicTool.Location = toolScreenLocation;
  915. depthExtensionPicTool.Tag = toolTag;
  916. listDepthExtensionPicTool[i].Location = oldToolLocation;
  917. listDepthExtensionPicTool[i].Tag = oldToolTag;
  918. this.panel2.Refresh();
  919. return;
  920. }
  921. }
  922. }
  923. //如果鼠标点不与其他自定义控件重合,则当前拖动控件回到原始点
  924. depthExtensionPicTool.Location = oldToolLocation;
  925. }
  926. /// <summary>
  927. /// 图片自定义控件的鼠标拖动事件
  928. /// </summary>
  929. /// <param name="sender"></param>
  930. /// <param name="e"></param>
  931. private void picTool_MouseMove(object sender, MouseEventArgs e)
  932. {
  933. int _x = 0;
  934. int _y = 0;
  935. if (isMouseDown)
  936. {
  937. Point pt = Control.MousePosition;
  938. _x = mouseOffset.X - pt.X;
  939. _y = mouseOffset.Y - pt.Y;
  940. PictureBox pictureBox = (PictureBox)sender;
  941. ((DepthExtensionPicTool)pictureBox.Parent).Cursor = Cursors.SizeAll;
  942. ((DepthExtensionPicTool)pictureBox.Parent).Location = new Point(picToolLocation.X - _x, picToolLocation.Y - _y);
  943. }
  944. }
  945. /// <summary>
  946. /// 第三步按钮
  947. /// </summary>
  948. /// <param name="sender"></param>
  949. /// <param name="e"></param>
  950. private void button3_Click(object sender, EventArgs e)
  951. {
  952. if (this.groupBox6.Visible && this.groupBox7.Visible)
  953. return;
  954. ChangeButtonStyle(this.button3, this.button1, this.button2);
  955. this.groupBox2.Visible = false;
  956. this.groupBox3.Visible = false;
  957. this.groupBoxStep2Operate.Visible = false;
  958. this.groupBox5.Visible = false;
  959. this.groupBox6.Visible = true;
  960. this.groupBox7.Visible = true;
  961. this.textBox3.Text = PdnResources.GetString("Menu.Image.Text") + "-" + PdnResources.GetString("Menu.ImageCollection.ImageStitching.Text") + "-" + stepNumber;
  962. this.pictureBox1.Image = null;
  963. this._mosaicsImage = null;
  964. //获取第二步的所有图片
  965. List<Bitmap> bitmapList = new List<Bitmap>();
  966. List<int> tagList = new List<int>();
  967. foreach (Control C in this.panel2.Controls)
  968. {
  969. if (C is DepthExtensionPicTool)
  970. {
  971. DepthExtensionPicTool depthExtensionPicTool = (DepthExtensionPicTool)C;
  972. if (depthExtensionPicTool.pictureBox1.Image != null)
  973. {
  974. bitmapList.Add((Bitmap)(depthExtensionPicTool.pictureBox1.Image));
  975. tagList.Add((int)depthExtensionPicTool.Tag);
  976. }
  977. }
  978. }
  979. if (bitmapList.Count < 2)//少于两张图时不做处理
  980. {
  981. MessageBox.Show(PdnResources.GetString("Menu.Imporlessthatwopicturesunabletojoin.Text"));
  982. return;
  983. }
  984. else
  985. {
  986. OpenCvSharp.Mat[] mats = new OpenCvSharp.Mat[bitmapList.Count];
  987. int index = 0;
  988. foreach (Bitmap bitmap in bitmapList)
  989. {
  990. var i = tagList[index] - 1;
  991. mats[i] = OpenCvSharp.Extensions.BitmapConverter.ToMat(bitmapList[index]);
  992. index++;
  993. }
  994. ////进行图片拼接
  995. Boolean errorFlag = false;
  996. //OpenCvSharp.Mat mat = AdjustIntent.MatchPicByXFeatures2D(mats, out errorFlag);
  997. int colNum = this.tbxColunmN.Text == "" ? 0 : Convert.ToInt32(this.tbxColunmN.Text);//列数
  998. double rate = (double)numOverlapRate.Value;
  999. OpenCvSharp.Mat mat = AdjustIntent.MatchPicOneByOne2D(mats, colNum, rate, out errorFlag/*, false*/);
  1000. if (errorFlag || mat.Width < 1 || mat.Height < 1)//宽高大于0代表拼接成功,只能操作可拼接的图片
  1001. {
  1002. MessageBox.Show(PdnResources.GetString("Menu.ImageMosaicfailed.Text"));
  1003. return;
  1004. }
  1005. _mosaicsImage = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(mat);
  1006. if (_mosaicsImage != null)
  1007. {
  1008. if (_mosaicsImage.Width > this.pictureBox1.Size.Width || _mosaicsImage.Height > this.pictureBox1.Size.Height)
  1009. {
  1010. this.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
  1011. }
  1012. else
  1013. {
  1014. this.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
  1015. }
  1016. this.pictureBox1.Image = _mosaicsImage;
  1017. }
  1018. }
  1019. _lastPoint = new Point(0, 0);
  1020. _isFirst = true;
  1021. }
  1022. /// <summary>
  1023. /// 修改第X步的按钮样式
  1024. /// </summary>
  1025. /// <param name="displayButton">要修改的按钮</param>
  1026. /// <param name="hideButton1">要恢复的按钮1</param>
  1027. /// <param name="hideButton2">要恢复的按钮2</param>
  1028. private void ChangeButtonStyle(Button displayButton, Button hideButton1, Button hideButton2)
  1029. {
  1030. hideButton1.BackColor = Color.FromArgb(255, 240, 240, 240);
  1031. hideButton1.ForeColor = Color.FromArgb(255, 0, 0, 0);
  1032. hideButton1.FlatStyle = FlatStyle.Standard;
  1033. hideButton1.FlatAppearance.BorderSize = 1;
  1034. hideButton2.BackColor = Color.FromArgb(255, 240, 240, 240);
  1035. hideButton2.ForeColor = Color.FromArgb(255, 0, 0, 0);
  1036. hideButton2.FlatStyle = FlatStyle.Standard;
  1037. hideButton2.FlatAppearance.BorderSize = 1;
  1038. displayButton.BackColor = Color.Gray;
  1039. displayButton.ForeColor = Color.White;
  1040. displayButton.FlatStyle = FlatStyle.Flat;
  1041. displayButton.FlatAppearance.BorderSize = 0;
  1042. }
  1043. /// <summary>
  1044. /// 绘制删除图标
  1045. /// </summary>
  1046. /// <param name="sender"></param>
  1047. /// <param name="e"></param>
  1048. private void panelDel_Paint(object sender, PaintEventArgs e)
  1049. {
  1050. Image deleteImg = PdnResources.GetImageResource("Images.ImageStrip.CloseButton.Hot.png").Reference;//从项目中随便找了一个红色的删除图片
  1051. if (deleteImg != null)
  1052. {
  1053. Graphics g = e.Graphics;
  1054. g.DrawImage(deleteImg, 0, 0);
  1055. }
  1056. }
  1057. /// <summary>
  1058. /// 绘制添加功能的十字线
  1059. /// </summary>
  1060. /// <param name="sender"></param>
  1061. /// <param name="e"></param>
  1062. private void panelAdd_Paint(object sender, PaintEventArgs e)
  1063. {
  1064. Panel panel = (Panel)sender;
  1065. Size panelSize = panel.Size;
  1066. Graphics g = e.Graphics;
  1067. Pen linePen = new Pen(Color.Black);
  1068. linePen.Width = 3;
  1069. g.DrawLine(linePen, new Point(0, panelSize.Height / 2), new Point(panelSize.Width, panelSize.Height / 2));
  1070. g.DrawLine(linePen, new Point(panelSize.Width / 2, 0), new Point(panelSize.Width / 2, panelSize.Height));
  1071. linePen.Dispose();
  1072. }
  1073. /// <summary>
  1074. /// 点击添加标志
  1075. /// </summary>
  1076. /// <param name="sender"></param>
  1077. /// <param name="e"></param>
  1078. private void panelAdd_Click(object sender, EventArgs e)
  1079. {
  1080. Bitmap bitmap = ChooseImageFromHardDisk();
  1081. if (bitmap != null)
  1082. {
  1083. Panel panel = (Panel)sender;
  1084. DepthExtensionPicTool parentTool = (DepthExtensionPicTool)panel.Parent;
  1085. if (bitmap.Width > parentTool.pictureBox1.Size.Width || bitmap.Height > parentTool.pictureBox1.Size.Height)
  1086. {
  1087. parentTool.pictureBox1.SizeMode = PictureBoxSizeMode.Zoom;
  1088. }
  1089. else
  1090. {
  1091. parentTool.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
  1092. }
  1093. parentTool.pictureBox1.Image = bitmap;
  1094. parentTool.panel2.Visible = false;
  1095. parentTool.panel1.Visible = true;
  1096. }
  1097. }
  1098. /// <summary>
  1099. /// 点击删除图标
  1100. /// </summary>
  1101. /// <param name="sender"></param>
  1102. /// <param name="e"></param>
  1103. private void panelDel_Click(object sender, EventArgs e)
  1104. {
  1105. Panel panel = (Panel)sender;
  1106. DepthExtensionPicTool parentTool = (DepthExtensionPicTool)panel.Parent;
  1107. if (parentTool.pictureBox1.Image != null)
  1108. {
  1109. parentTool.pictureBox1.Image = null;
  1110. parentTool.panel2.Visible = true;
  1111. parentTool.panel1.Visible = false;
  1112. }
  1113. }
  1114. /// <summary>
  1115. /// 点击倒置按钮
  1116. /// </summary>
  1117. /// <param name="sender"></param>
  1118. /// <param name="e"></param>
  1119. private void convertButton_Click(object sender, EventArgs e)
  1120. {
  1121. Button convertBtn = (Button)sender;
  1122. int rowNum = 0;
  1123. if (convertBtn.Tag != null && convertBtn.Tag.ToString().Length > 0)
  1124. {
  1125. rowNum = Convert.ToInt32(convertBtn.Tag.ToString());//button的tag值确定是第几行
  1126. }
  1127. if (rowNum > 0)
  1128. {
  1129. int colNum = this.tbxColunmN.Text == "" ? 0 : Convert.ToInt32(this.tbxColunmN.Text);//列数
  1130. //取得点击按钮所在行的图片自定义控件tag的最大值与最小值
  1131. int minTag = colNum * (rowNum - 1) + 1;
  1132. int maxTag = colNum * rowNum;
  1133. //取得所有图片自定义控件的list
  1134. List<DepthExtensionPicTool> picToolList = new List<DepthExtensionPicTool>();
  1135. foreach (Control C in this.panel2.Controls)
  1136. {
  1137. if (C is DepthExtensionPicTool)
  1138. {
  1139. picToolList.Add((DepthExtensionPicTool)C);
  1140. }
  1141. }
  1142. //取得tag值所对应的图片自定义控件对象
  1143. List<DepthExtensionPicTool> convertPicToolList = picToolList.FindAll(a => Convert.ToInt32(a.Tag) >= minTag && Convert.ToInt32(a.Tag) <= maxTag);
  1144. convertPicToolList = convertPicToolList.OrderBy(a => a.Location.X).ToList();//按location重新排序
  1145. List<Point> locationPoint = new List<Point>(convertPicToolList.Select(a => a.Location).ToList());//取得这些对象的location
  1146. //反转后再重新赋回去
  1147. locationPoint.Reverse();
  1148. for (int j = 0; j < convertPicToolList.Count; j++)
  1149. {
  1150. convertPicToolList[j].Location = locationPoint[j];
  1151. }
  1152. for (int j = 0; j < convertPicToolList.Count / 2; j++)
  1153. {
  1154. int tag1 = (int)convertPicToolList[j].Tag;
  1155. convertPicToolList[j].Tag = (int)convertPicToolList[convertPicToolList.Count - j - 1].Tag;
  1156. convertPicToolList[convertPicToolList.Count - j - 1].Tag = tag1;
  1157. }
  1158. }
  1159. }
  1160. /// <summary>
  1161. /// 保存按钮
  1162. /// </summary>
  1163. /// <param name="sender"></param>
  1164. /// <param name="e"></param>
  1165. private void button8_Click(object sender, EventArgs e)
  1166. {
  1167. if (this.pictureBox1.Image != null && _mosaicsImage != null)
  1168. {
  1169. double widthRatio = imageRect.Width / (_mosaicsImage.Width * 1d);//缩略图与原图的宽度比
  1170. double heightRatio = imageRect.Height / (_mosaicsImage.Height * 1d);//缩略图与原图的高度比
  1171. int xc = (this.pictureBox1.Width - this.imageRect.Width) / 2;//缩略图横坐标与控件原点的偏移量
  1172. int yc = (this.pictureBox1.Height - this.imageRect.Height) / 2;//缩略图纵坐标与控件原点的偏移量
  1173. int cutX = Convert.ToInt32((zoomRect.X - xc) / widthRatio);
  1174. int cutY = Convert.ToInt32((zoomRect.Y - yc) / heightRatio);
  1175. int cutWidth = Convert.ToInt32(zoomRect.Width / widthRatio);
  1176. int cutHeight = Convert.ToInt32(zoomRect.Height / heightRatio);
  1177. Bitmap cutBitmap = DrawRulerHelper.KiCut(new Bitmap(this.pictureBox1.Image), cutX, cutY, cutWidth, cutHeight);
  1178. if (cutBitmap != null)
  1179. {
  1180. DocumentWorkspace dw = appWorkspace.AddNewDocumentWorkspace();
  1181. Document document = Document.FromImage(cutBitmap);
  1182. dw.Document = document;
  1183. dw.xmlSaveModel = Startup.instance.ruleDB;
  1184. dw.InitRulerInfo();
  1185. dw.fileText = this.textBox3.Text;
  1186. appWorkspace.ActiveDocumentWorkspace = dw;
  1187. }
  1188. }
  1189. }
  1190. /// <summary>
  1191. /// 绘制picturebox中的矩形框
  1192. /// </summary>
  1193. /// <param name="sender"></param>
  1194. /// <param name="e"></param>
  1195. private void pictureBox1_Paint(object sender, PaintEventArgs e)
  1196. {
  1197. if (this.pictureBox1.Image != null)
  1198. {
  1199. Pen rectPen = new Pen(Color.LightGreen);
  1200. rectPen.Width = 3;
  1201. if (_isFirst)
  1202. {
  1203. //获取缩略图对应矩形
  1204. PropertyInfo _ImageRectanglePropert = this.pictureBox1.GetType().GetProperty("ImageRectangle", BindingFlags.Instance | BindingFlags.NonPublic);
  1205. imageRect = (Rectangle)_ImageRectanglePropert.GetValue(this.pictureBox1, null);
  1206. zoomRect = new Rectangle(imageRect.X, imageRect.Y, imageRect.Width, imageRect.Height);
  1207. }
  1208. e.Graphics.DrawRectangle(rectPen, zoomRect.X, zoomRect.Y, zoomRect.Width - 1, zoomRect.Height - 1);
  1209. e.Graphics.FillRectangle(new SolidBrush(Color.Black), new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 7, 7));
  1210. rectPen.Dispose();
  1211. }
  1212. }
  1213. /// <summary>
  1214. /// 矩形框的选中
  1215. /// </summary>
  1216. /// <param name="sender"></param>
  1217. /// <param name="e"></param>
  1218. private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
  1219. {
  1220. _lastPoint.X = e.X;
  1221. _lastPoint.Y = e.Y;
  1222. //是否平移
  1223. if (zoomRect.Contains(e.Location) && !new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 7, 7).Contains(e.Location))
  1224. isMoved = true;
  1225. else
  1226. isMoved = false;
  1227. //是否调整大小
  1228. if (new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 7, 7).Contains(e.Location))
  1229. isResized = true;
  1230. else
  1231. isResized = false;
  1232. }
  1233. /// <summary>
  1234. /// 矩形框的拖动和改变大小
  1235. /// </summary>
  1236. /// <param name="sender"></param>
  1237. /// <param name="e"></param>
  1238. private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
  1239. {
  1240. //修改鼠标形状
  1241. this.pictureBox1.Cursor = Cursors.Default;
  1242. if (zoomRect != null)
  1243. {
  1244. if (zoomRect.Contains(e.Location) && !new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 7, 7).Contains(e.Location))
  1245. {
  1246. this.pictureBox1.Cursor = Cursors.SizeAll;
  1247. }
  1248. if (new Rectangle(zoomRect.Right - 5, zoomRect.Bottom - 5, 7, 7).Contains(e.Location))
  1249. {
  1250. this.pictureBox1.Cursor = Cursors.SizeNWSE;
  1251. }
  1252. }
  1253. if (e.Button != MouseButtons.Left)
  1254. return;
  1255. //拖拽
  1256. if (zoomRect != null && isMoved)
  1257. {
  1258. _isFirst = false;
  1259. Point p = e.Location;
  1260. int dx = p.X - _lastPoint.X;
  1261. int dy = p.Y - _lastPoint.Y;
  1262. _lastPoint.X = p.X;
  1263. _lastPoint.Y = p.Y;
  1264. zoomRect.X += dx;
  1265. zoomRect.Y += dy;
  1266. //控制矩形框不超过缩略图尺寸
  1267. int xc = (this.pictureBox1.Width - this.imageRect.Width) / 2;
  1268. int yc = (this.pictureBox1.Height - this.imageRect.Height) / 2;
  1269. if (zoomRect.X < xc) zoomRect.X = xc;
  1270. if (zoomRect.Y < yc) zoomRect.Y = yc;
  1271. if (zoomRect.X + zoomRect.Width > imageRect.Width + xc) zoomRect.X = imageRect.Width - zoomRect.Width + xc;
  1272. if (zoomRect.Y + zoomRect.Height > imageRect.Height + yc) zoomRect.Y = imageRect.Height - zoomRect.Height + yc;
  1273. this.pictureBox1.Refresh();
  1274. }
  1275. //调整大小
  1276. if (zoomRect != null && isResized)
  1277. {
  1278. _isFirst = false;
  1279. Point p = e.Location;
  1280. //不允许超出矩形框的原点
  1281. if (p.X < zoomRect.X + 5)
  1282. {
  1283. p.X = zoomRect.X + 5;
  1284. }
  1285. if (p.Y < zoomRect.Y + 5)
  1286. {
  1287. p.Y = zoomRect.Y + 5;
  1288. }
  1289. //修改矩形框尺寸
  1290. int top = zoomRect.Top;
  1291. int left = zoomRect.Left;
  1292. int right = zoomRect.Right;
  1293. int bottom = zoomRect.Bottom;
  1294. right = p.X;
  1295. bottom = p.Y;
  1296. zoomRect = new Rectangle(left, top, right - left, bottom - top);
  1297. //控制矩形框不超过缩略图尺寸
  1298. int xc = (this.pictureBox1.Width - this.imageRect.Width) / 2;
  1299. int yc = (this.pictureBox1.Height - this.imageRect.Height) / 2;
  1300. if (zoomRect.X < xc) zoomRect.X = xc;
  1301. if (zoomRect.Y < yc) zoomRect.Y = yc;
  1302. if (zoomRect.X + zoomRect.Width > imageRect.Width + xc) zoomRect.Width = imageRect.Width + xc - zoomRect.X;
  1303. if (zoomRect.Y + zoomRect.Height > imageRect.Height + yc) zoomRect.Height = imageRect.Height + yc - zoomRect.Y;
  1304. this.pictureBox1.Refresh();
  1305. }
  1306. }
  1307. /// <summary>
  1308. /// 返回按钮
  1309. /// </summary>
  1310. /// <param name="sender"></param>
  1311. /// <param name="e"></param>
  1312. private void button5_Click(object sender, EventArgs e)
  1313. {
  1314. //第二步
  1315. if (this.groupBox6.Visible && this.groupBox7.Visible)
  1316. {
  1317. this.button2.PerformClick();
  1318. return;
  1319. }
  1320. //第一步
  1321. if (this.groupBoxStep2Operate.Visible && this.groupBox5.Visible)
  1322. {
  1323. this.button1.PerformClick();
  1324. return;
  1325. }
  1326. }
  1327. /// <summary>
  1328. /// 下一步按钮
  1329. /// </summary>
  1330. /// <param name="sender"></param>
  1331. /// <param name="e"></param>
  1332. private void button4_Click(object sender, EventArgs e)
  1333. {
  1334. //第二步
  1335. if (this.groupBox2.Visible && this.groupBox3.Visible)
  1336. {
  1337. this.button2.PerformClick();
  1338. return;
  1339. }
  1340. //第三步
  1341. if (this.groupBoxStep2Operate.Visible && this.groupBox5.Visible)
  1342. {
  1343. this.button3.PerformClick();
  1344. return;
  1345. }
  1346. }
  1347. }
  1348. }