ImageInformation.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. using PaintDotNet.Base.CommTool;
  2. using PaintDotNet.Base.SettingModel;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Globalization;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. namespace PaintDotNet.Instrument
  15. {
  16. internal class ImageInformation : PdnBaseForm
  17. {
  18. private GroupBox groupBox1;
  19. private GroupBox groupBox2;
  20. private Label label1;
  21. private Label label9;
  22. private Label label8;
  23. private Label label7;
  24. private Label label6;
  25. private RichTextBox richTextBox1;
  26. private TextBox textBox4;
  27. private Label label5;
  28. private Label label4;
  29. private Label label3;
  30. private Label label2;
  31. private TextBox textBox1;
  32. private TextBox textBox8;
  33. private TextBox textBox7;
  34. private TextBox textBox6;
  35. private TextBox textBox5;
  36. private ComboBox comboBox1;
  37. private DateTimePicker dateTimePicker1;
  38. private Button button1;
  39. private AppWorkspace appWorkspace;
  40. public ImageInformation(AppWorkspace appWorkspace)
  41. {
  42. this.appWorkspace = appWorkspace;
  43. InitializeComponent();
  44. InitializeLanguageText();
  45. InitializeInformation();
  46. }
  47. private void InitializeLanguageText()
  48. {
  49. this.groupBox1.Text = PdnResources.GetString("Menu.operation.text");
  50. this.button1.Text = PdnResources.GetString("Menu.File.Close.Text");
  51. this.groupBox2.Text = PdnResources.GetString("Menu.information.text");
  52. this.label9.Text = PdnResources.GetString("Menu.timeofexposure.text") + ":";
  53. this.label8.Text = PdnResources.GetString("Menu.magnificationchanger.text") + ":";
  54. this.label7.Text = PdnResources.GetString("Menu.Objectlens.text") + ":";
  55. this.label6.Text = PdnResources.GetString("Menu.microscope.text") + ":";
  56. this.label5.Text = PdnResources.GetString("Menu.tool.imageinformation.Imageannotation.text") + ":";
  57. this.label4.Text = PdnResources.GetString("Menu.tool.imageinformation.Imagesize.text") + ":";
  58. this.label3.Text = PdnResources.GetString("Menu.tool.imageinformation.Createdate.text") + ":";
  59. this.label2.Text = PdnResources.GetString("Menu.tool.imageinformation.Imageformat.text") + ":";
  60. this.label1.Text = PdnResources.GetString("Menu.Imagename.text") + ":";
  61. this.Text = PdnResources.GetString("Menu.Tools.ImageInfo.Text");
  62. }
  63. private void InitializeComponent()
  64. {
  65. this.groupBox1 = new System.Windows.Forms.GroupBox();
  66. this.button1 = new System.Windows.Forms.Button();
  67. this.groupBox2 = new System.Windows.Forms.GroupBox();
  68. this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
  69. this.comboBox1 = new System.Windows.Forms.ComboBox();
  70. this.textBox8 = new System.Windows.Forms.TextBox();
  71. this.textBox7 = new System.Windows.Forms.TextBox();
  72. this.textBox6 = new System.Windows.Forms.TextBox();
  73. this.textBox5 = new System.Windows.Forms.TextBox();
  74. this.label9 = new System.Windows.Forms.Label();
  75. this.label8 = new System.Windows.Forms.Label();
  76. this.label7 = new System.Windows.Forms.Label();
  77. this.label6 = new System.Windows.Forms.Label();
  78. this.richTextBox1 = new System.Windows.Forms.RichTextBox();
  79. this.textBox4 = new System.Windows.Forms.TextBox();
  80. this.label5 = new System.Windows.Forms.Label();
  81. this.label4 = new System.Windows.Forms.Label();
  82. this.label3 = new System.Windows.Forms.Label();
  83. this.label2 = new System.Windows.Forms.Label();
  84. this.textBox1 = new System.Windows.Forms.TextBox();
  85. this.label1 = new System.Windows.Forms.Label();
  86. this.groupBox1.SuspendLayout();
  87. this.groupBox2.SuspendLayout();
  88. this.SuspendLayout();
  89. //
  90. // groupBox1
  91. //
  92. this.groupBox1.Controls.Add(this.button1);
  93. this.groupBox1.Location = new System.Drawing.Point(13, 13);
  94. this.groupBox1.Name = "groupBox1";
  95. this.groupBox1.Size = new System.Drawing.Size(403, 56);
  96. this.groupBox1.TabIndex = 1;
  97. this.groupBox1.TabStop = false;
  98. this.groupBox1.Text = "操作";
  99. //
  100. // button1
  101. //
  102. this.button1.Location = new System.Drawing.Point(306, 20);
  103. this.button1.Name = "button1";
  104. this.button1.Size = new System.Drawing.Size(75, 23);
  105. this.button1.TabIndex = 0;
  106. this.button1.Text = "关闭";
  107. this.button1.UseVisualStyleBackColor = true;
  108. this.button1.Click += new System.EventHandler(this.button1_Click);
  109. //
  110. // groupBox2
  111. //
  112. this.groupBox2.Controls.Add(this.dateTimePicker1);
  113. this.groupBox2.Controls.Add(this.comboBox1);
  114. this.groupBox2.Controls.Add(this.textBox8);
  115. this.groupBox2.Controls.Add(this.textBox7);
  116. this.groupBox2.Controls.Add(this.textBox6);
  117. this.groupBox2.Controls.Add(this.textBox5);
  118. this.groupBox2.Controls.Add(this.label9);
  119. this.groupBox2.Controls.Add(this.label8);
  120. this.groupBox2.Controls.Add(this.label7);
  121. this.groupBox2.Controls.Add(this.label6);
  122. this.groupBox2.Controls.Add(this.richTextBox1);
  123. this.groupBox2.Controls.Add(this.textBox4);
  124. this.groupBox2.Controls.Add(this.label5);
  125. this.groupBox2.Controls.Add(this.label4);
  126. this.groupBox2.Controls.Add(this.label3);
  127. this.groupBox2.Controls.Add(this.label2);
  128. this.groupBox2.Controls.Add(this.textBox1);
  129. this.groupBox2.Controls.Add(this.label1);
  130. this.groupBox2.Location = new System.Drawing.Point(13, 86);
  131. this.groupBox2.Name = "groupBox2";
  132. this.groupBox2.Size = new System.Drawing.Size(403, 464);
  133. this.groupBox2.TabIndex = 2;
  134. this.groupBox2.TabStop = false;
  135. this.groupBox2.Text = "信息";
  136. //
  137. // dateTimePicker1
  138. //
  139. this.dateTimePicker1.CustomFormat = "yyyy/MM/dd HH:mm:ss";
  140. this.dateTimePicker1.Enabled = false;
  141. this.dateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
  142. this.dateTimePicker1.Location = new System.Drawing.Point(89, 91);
  143. this.dateTimePicker1.Name = "dateTimePicker1";
  144. this.dateTimePicker1.Size = new System.Drawing.Size(275, 21);
  145. this.dateTimePicker1.TabIndex = 19;
  146. //
  147. // comboBox1
  148. //
  149. this.comboBox1.Enabled = false;
  150. this.comboBox1.FormattingEnabled = true;
  151. this.comboBox1.Location = new System.Drawing.Point(89, 59);
  152. this.comboBox1.Name = "comboBox1";
  153. this.comboBox1.Size = new System.Drawing.Size(275, 20);
  154. this.comboBox1.TabIndex = 18;
  155. //
  156. // textBox8
  157. //
  158. this.textBox8.Location = new System.Drawing.Point(89, 428);
  159. this.textBox8.Name = "textBox8";
  160. this.textBox8.ReadOnly = true;
  161. this.textBox8.Size = new System.Drawing.Size(275, 21);
  162. this.textBox8.TabIndex = 17;
  163. //
  164. // textBox7
  165. //
  166. this.textBox7.Location = new System.Drawing.Point(89, 394);
  167. this.textBox7.Name = "textBox7";
  168. this.textBox7.ReadOnly = true;
  169. this.textBox7.Size = new System.Drawing.Size(275, 21);
  170. this.textBox7.TabIndex = 16;
  171. //
  172. // textBox6
  173. //
  174. this.textBox6.Location = new System.Drawing.Point(89, 357);
  175. this.textBox6.Name = "textBox6";
  176. this.textBox6.ReadOnly = true;
  177. this.textBox6.Size = new System.Drawing.Size(275, 21);
  178. this.textBox6.TabIndex = 15;
  179. //
  180. // textBox5
  181. //
  182. this.textBox5.Location = new System.Drawing.Point(89, 322);
  183. this.textBox5.Name = "textBox5";
  184. this.textBox5.ReadOnly = true;
  185. this.textBox5.Size = new System.Drawing.Size(275, 21);
  186. this.textBox5.TabIndex = 14;
  187. //
  188. // label9
  189. //
  190. this.label9.AutoSize = true;
  191. this.label9.Location = new System.Drawing.Point(18, 431);
  192. this.label9.Name = "label9";
  193. this.label9.Size = new System.Drawing.Size(65, 12);
  194. this.label9.TabIndex = 13;
  195. this.label9.Text = "曝光时间:";
  196. //
  197. // label8
  198. //
  199. this.label8.AutoSize = true;
  200. this.label8.Location = new System.Drawing.Point(18, 397);
  201. this.label8.Name = "label8";
  202. this.label8.Size = new System.Drawing.Size(53, 12);
  203. this.label8.TabIndex = 12;
  204. this.label8.Text = "变倍器:";
  205. //
  206. // label7
  207. //
  208. this.label7.AutoSize = true;
  209. this.label7.Location = new System.Drawing.Point(18, 360);
  210. this.label7.Name = "label7";
  211. this.label7.Size = new System.Drawing.Size(41, 12);
  212. this.label7.TabIndex = 11;
  213. this.label7.Text = "物镜:";
  214. //
  215. // label6
  216. //
  217. this.label6.AutoSize = true;
  218. this.label6.Location = new System.Drawing.Point(18, 325);
  219. this.label6.Name = "label6";
  220. this.label6.Size = new System.Drawing.Size(53, 12);
  221. this.label6.TabIndex = 10;
  222. this.label6.Text = "显微镜:";
  223. //
  224. // richTextBox1
  225. //
  226. this.richTextBox1.Location = new System.Drawing.Point(89, 175);
  227. this.richTextBox1.Name = "richTextBox1";
  228. this.richTextBox1.ReadOnly = true;
  229. this.richTextBox1.Size = new System.Drawing.Size(275, 128);
  230. this.richTextBox1.TabIndex = 9;
  231. this.richTextBox1.Text = "";
  232. //
  233. // textBox4
  234. //
  235. this.textBox4.Location = new System.Drawing.Point(89, 132);
  236. this.textBox4.Name = "textBox4";
  237. this.textBox4.ReadOnly = true;
  238. this.textBox4.Size = new System.Drawing.Size(275, 21);
  239. this.textBox4.TabIndex = 8;
  240. //
  241. // label5
  242. //
  243. this.label5.AutoSize = true;
  244. this.label5.Location = new System.Drawing.Point(18, 190);
  245. this.label5.Name = "label5";
  246. this.label5.Size = new System.Drawing.Size(65, 12);
  247. this.label5.TabIndex = 5;
  248. this.label5.Text = "图像注释:";
  249. //
  250. // label4
  251. //
  252. this.label4.AutoSize = true;
  253. this.label4.Location = new System.Drawing.Point(16, 135);
  254. this.label4.Name = "label4";
  255. this.label4.Size = new System.Drawing.Size(65, 12);
  256. this.label4.TabIndex = 4;
  257. this.label4.Text = "图像大小:";
  258. //
  259. // label3
  260. //
  261. this.label3.AutoSize = true;
  262. this.label3.Location = new System.Drawing.Point(16, 97);
  263. this.label3.Name = "label3";
  264. this.label3.Size = new System.Drawing.Size(65, 12);
  265. this.label3.TabIndex = 3;
  266. this.label3.Text = "创建日期:";
  267. //
  268. // label2
  269. //
  270. this.label2.AutoSize = true;
  271. this.label2.Location = new System.Drawing.Point(16, 62);
  272. this.label2.Name = "label2";
  273. this.label2.Size = new System.Drawing.Size(65, 12);
  274. this.label2.TabIndex = 2;
  275. this.label2.Text = "图像格式:";
  276. //
  277. // textBox1
  278. //
  279. this.textBox1.Location = new System.Drawing.Point(89, 23);
  280. this.textBox1.Name = "textBox1";
  281. this.textBox1.ReadOnly = true;
  282. this.textBox1.Size = new System.Drawing.Size(275, 21);
  283. this.textBox1.TabIndex = 1;
  284. //
  285. // label1
  286. //
  287. this.label1.AutoSize = true;
  288. this.label1.Location = new System.Drawing.Point(16, 26);
  289. this.label1.Name = "label1";
  290. this.label1.Size = new System.Drawing.Size(65, 12);
  291. this.label1.TabIndex = 0;
  292. this.label1.Text = "图像名称:";
  293. //
  294. // ImageInformation
  295. //
  296. this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
  297. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
  298. this.ClientSize = new System.Drawing.Size(428, 562);
  299. this.Controls.Add(this.groupBox2);
  300. this.Controls.Add(this.groupBox1);
  301. this.MaximizeBox = false;
  302. this.MinimizeBox = false;
  303. this.Name = "ImageInformation";
  304. this.Text = "图片信息";
  305. this.Controls.SetChildIndex(this.groupBox1, 0);
  306. this.Controls.SetChildIndex(this.groupBox2, 0);
  307. this.groupBox1.ResumeLayout(false);
  308. this.groupBox2.ResumeLayout(false);
  309. this.groupBox2.PerformLayout();
  310. this.ResumeLayout(false);
  311. }
  312. /// <summary>
  313. /// 关闭
  314. /// </summary>
  315. /// <param name="sender"></param>
  316. /// <param name="e"></param>
  317. private void button1_Click(object sender, EventArgs e)
  318. {
  319. this.Close();
  320. }
  321. private void InitializeInformation()
  322. {
  323. if (this.appWorkspace.ActiveDocumentWorkspace != null)
  324. {
  325. if (this.appWorkspace.ActiveDocumentWorkspace.CompositionSurface != null)
  326. {
  327. //获取图片路径
  328. string fileName;
  329. //FileType fileType;
  330. //SaveConfigToken saveConfigToken;
  331. this.appWorkspace.ActiveDocumentWorkspace.GetDocumentSaveOptions(out fileName/*, out fileType, out saveConfigToken*/);
  332. if (fileName != null)
  333. {
  334. //获取图片对应xml
  335. PicConfigModel configModel = null;
  336. try
  337. {
  338. string path = Path.GetDirectoryName(fileName);
  339. string xmlPath = path + "\\" + Path.GetFileNameWithoutExtension(fileName) + ".xml";
  340. //如果xml存在
  341. if (System.IO.File.Exists(xmlPath))
  342. {
  343. configModel = XmlSerializeHelper.DESerializer<PicConfigModel>(FileOperationHelper.ReadStringFromFile(xmlPath, FileMode.Open));
  344. if (configModel != null)
  345. {
  346. this.textBox1.Text = configModel.meta.text;
  347. this.comboBox1.Text = configModel.meta.format;
  348. if (configModel.meta.createdTime != null && configModel.meta.createdTime != "")
  349. {
  350. this.dateTimePicker1.Value = Convert.ToDateTime(configModel.meta.createdTime);
  351. }
  352. this.textBox4.Text = configModel.meta.imageSize;
  353. this.textBox5.Text = configModel.hardware.microscope;
  354. this.textBox6.Text = configModel.hardware.objective;
  355. this.textBox7.Text = configModel.hardware.magnificationChanger;
  356. this.textBox8.Text = configModel.hardware.exposureTime;
  357. }
  358. }
  359. else
  360. {
  361. //获取图片信息
  362. if (System.IO.File.Exists(fileName))
  363. {
  364. FileInfo fi = new FileInfo(fileName);
  365. this.textBox1.Text = System.IO.Path.GetFileNameWithoutExtension(fileName);
  366. this.comboBox1.Text = Path.GetExtension(fileName);//fileType.Name;
  367. this.dateTimePicker1.Value = fi.CreationTime;
  368. this.textBox4.Text = FileOperationHelper.GetLength(fi.Length);
  369. }
  370. else
  371. {
  372. clearDateTimePicker();
  373. }
  374. }
  375. }
  376. catch (Exception)
  377. {
  378. clearDateTimePicker();
  379. }
  380. }
  381. else
  382. {
  383. clearDateTimePicker();
  384. }
  385. }
  386. else
  387. {
  388. clearDateTimePicker();
  389. }
  390. }
  391. else
  392. {
  393. clearDateTimePicker();
  394. }
  395. }
  396. /// <summary>
  397. /// 清空日期控件的显示数据,默认会显示当前时间
  398. /// </summary>
  399. private void clearDateTimePicker()
  400. {
  401. this.dateTimePicker1.CustomFormat = " ";
  402. }
  403. }
  404. }