MySaveDialogControl.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Drawing.Imaging;
  11. using System.IO;
  12. using PaintDotNet.SystemLayer.FileDlgExtenders.FileDialogExtenders;
  13. namespace PaintDotNet.File
  14. {
  15. public partial class MySaveDialogControl : FileDialogControlBase
  16. {
  17. /// <summary>
  18. /// 必需的设计器变量。
  19. /// </summary>
  20. private System.ComponentModel.IContainer components = null;
  21. #region 组件设计器生成的代码
  22. private void InitializeLanguageText()
  23. {
  24. this.checkBox5.Text = PdnResources.GetString("Menu.Compressionratio.text");
  25. this.checkBox4.Text = PdnResources.GetString("Menu.Annotationandmddedintheimage.text");
  26. this.checkBox3.Text = PdnResources.GetString("Menu.Savegriddata.text");
  27. this.checkBox2.Text = PdnResources.GetString("Menu.Closeimageaftersaving.text");
  28. this.checkBox1.Text = PdnResources.GetString("Menu.Generateconfigurationfile.text");
  29. this.FileDlgCaption = PdnResources.GetString("Menu.file.Saveall.Savetheimagefileas.text");
  30. }
  31. /// <summary>
  32. /// 设计器支持所需的方法 - 不要修改
  33. /// 使用代码编辑器修改此方法的内容。
  34. /// </summary>
  35. private void InitializeComponent()
  36. {
  37. this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
  38. this.checkBox5 = new System.Windows.Forms.CheckBox();
  39. this.checkBox4 = new System.Windows.Forms.CheckBox();
  40. this.checkBox3 = new System.Windows.Forms.CheckBox();
  41. this.checkBox2 = new System.Windows.Forms.CheckBox();
  42. this.checkBox1 = new System.Windows.Forms.CheckBox();
  43. this.label1 = new System.Windows.Forms.Label();
  44. this.checkBox6 = new System.Windows.Forms.CheckBox();
  45. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
  46. this.SuspendLayout();
  47. //
  48. // numericUpDown1
  49. //
  50. this.numericUpDown1.Location = new System.Drawing.Point(176, 59);
  51. this.numericUpDown1.Margin = new System.Windows.Forms.Padding(2);
  52. this.numericUpDown1.Name = "numericUpDown1";
  53. this.numericUpDown1.Size = new System.Drawing.Size(41, 21);
  54. this.numericUpDown1.TabIndex = 15;
  55. //
  56. // checkBox5
  57. //
  58. this.checkBox5.AutoSize = true;
  59. this.checkBox5.Location = new System.Drawing.Point(103, 62);
  60. this.checkBox5.Margin = new System.Windows.Forms.Padding(2);
  61. this.checkBox5.Name = "checkBox5";
  62. this.checkBox5.Size = new System.Drawing.Size(72, 16);
  63. this.checkBox5.TabIndex = 14;
  64. this.checkBox5.Text = "压缩比例";
  65. this.checkBox5.UseVisualStyleBackColor = true;
  66. //
  67. // checkBox4
  68. //
  69. this.checkBox4.AutoSize = true;
  70. this.checkBox4.Location = new System.Drawing.Point(290, 36);
  71. this.checkBox4.Margin = new System.Windows.Forms.Padding(2);
  72. this.checkBox4.Name = "checkBox4";
  73. this.checkBox4.Size = new System.Drawing.Size(156, 16);
  74. this.checkBox4.TabIndex = 13;
  75. this.checkBox4.Text = "标注和测量信息嵌入图像";
  76. this.checkBox4.UseVisualStyleBackColor = true;
  77. //
  78. // checkBox3
  79. //
  80. this.checkBox3.AutoSize = true;
  81. this.checkBox3.Location = new System.Drawing.Point(103, 36);
  82. this.checkBox3.Margin = new System.Windows.Forms.Padding(2);
  83. this.checkBox3.Name = "checkBox3";
  84. this.checkBox3.Size = new System.Drawing.Size(96, 16);
  85. this.checkBox3.TabIndex = 12;
  86. this.checkBox3.Text = "保存网格数据";
  87. this.checkBox3.UseVisualStyleBackColor = true;
  88. //
  89. // checkBox2
  90. //
  91. this.checkBox2.AutoSize = true;
  92. this.checkBox2.Checked = true;
  93. this.checkBox2.CheckState = System.Windows.Forms.CheckState.Checked;
  94. this.checkBox2.Location = new System.Drawing.Point(290, 10);
  95. this.checkBox2.Margin = new System.Windows.Forms.Padding(2);
  96. this.checkBox2.Name = "checkBox2";
  97. this.checkBox2.Size = new System.Drawing.Size(108, 16);
  98. this.checkBox2.TabIndex = 11;
  99. this.checkBox2.Text = "保存后关闭图像";
  100. this.checkBox2.UseVisualStyleBackColor = true;
  101. //
  102. // checkBox1
  103. //
  104. this.checkBox1.AutoSize = true;
  105. this.checkBox1.Checked = true;
  106. this.checkBox1.CheckState = System.Windows.Forms.CheckState.Checked;
  107. this.checkBox1.Location = new System.Drawing.Point(103, 10);
  108. this.checkBox1.Margin = new System.Windows.Forms.Padding(2);
  109. this.checkBox1.Name = "checkBox1";
  110. this.checkBox1.Size = new System.Drawing.Size(96, 16);
  111. this.checkBox1.TabIndex = 10;
  112. this.checkBox1.Text = "生成配置文件";
  113. this.checkBox1.UseVisualStyleBackColor = true;
  114. //
  115. // label1
  116. //
  117. this.label1.AutoSize = true;
  118. this.label1.Font = new System.Drawing.Font("宋体", 12F);
  119. this.label1.Location = new System.Drawing.Point(220, 61);
  120. this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
  121. this.label1.Name = "label1";
  122. this.label1.Size = new System.Drawing.Size(16, 16);
  123. this.label1.TabIndex = 16;
  124. this.label1.Text = "%";
  125. //
  126. // checkBox6
  127. //
  128. this.checkBox6.AutoSize = true;
  129. this.checkBox6.Location = new System.Drawing.Point(290, 62);
  130. this.checkBox6.Name = "checkBox6";
  131. this.checkBox6.Size = new System.Drawing.Size(108, 16);
  132. this.checkBox6.TabIndex = 17;
  133. this.checkBox6.Text = "相信息嵌入图像";
  134. this.checkBox6.UseVisualStyleBackColor = true;
  135. //
  136. // MySaveDialogControl
  137. //
  138. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  139. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  140. this.Controls.Add(this.checkBox6);
  141. this.Controls.Add(this.label1);
  142. this.Controls.Add(this.numericUpDown1);
  143. this.Controls.Add(this.checkBox5);
  144. this.Controls.Add(this.checkBox4);
  145. this.Controls.Add(this.checkBox3);
  146. this.Controls.Add(this.checkBox2);
  147. this.Controls.Add(this.checkBox1);
  148. this.FileDlgCaption = "保存图像文件为";
  149. this.FileDlgStartLocation = PaintDotNet.SystemLayer.FileDlgExtenders.FileDialogExtenders.AddonWindowLocation.Bottom;
  150. this.Margin = new System.Windows.Forms.Padding(2);
  151. this.Name = "MySaveDialogControl";
  152. this.Size = new System.Drawing.Size(524, 101);
  153. ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
  154. this.ResumeLayout(false);
  155. this.PerformLayout();
  156. }
  157. #endregion
  158. ImageFormat _format = ImageFormat.Jpeg;
  159. System.IO.MemoryStream _memstream;
  160. public NumericUpDown numericUpDown1;
  161. public CheckBox checkBox5;
  162. public CheckBox checkBox4;
  163. public CheckBox checkBox3;
  164. public CheckBox checkBox2;
  165. public CheckBox checkBox1;
  166. public Label label1;
  167. public CheckBox checkBox6;
  168. string _imageFile;
  169. public MySaveDialogControl()
  170. {
  171. InitializeComponent();
  172. InitializeLanguageText();
  173. }
  174. protected override void OnPrepareMSDialog()
  175. {
  176. base.OnPrepareMSDialog();
  177. MSDialog.FilterIndex = GetIndexfromFile(_imageFile);
  178. if (Environment.OSVersion.Version.Major < 6)
  179. MSDialog.SetPlaces(new object[] { (int)Places.Desktop, (int)Places.Printers, (int)Places.Favorites, (int)Places.Programs, (int)Places.Fonts, });
  180. FileDlgInitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
  181. }
  182. public MySaveDialogControl(string originalfile, IWin32Window parent)
  183. {
  184. try
  185. {
  186. _imageFile = originalfile;
  187. //_originalImage = Image.FromFile(originalfile);
  188. }
  189. catch
  190. {
  191. _imageFile = null;
  192. }
  193. if (_imageFile == null || _imageFile.Length == 0)
  194. {
  195. //MyOpenFileDialogControl openDialog = new MyOpenFileDialogControl();
  196. //openDialog.FileDlgCheckFileExists = false;
  197. try
  198. {
  199. //if (parent == null)
  200. // parent = Application.OpenForms[0];
  201. //if (openDialog.ShowDialog(parent) == DialogResult.OK)
  202. //{
  203. //备注:这里处理保存按钮的点击事件
  204. //备注:下一个问题:为什么路径存在图片时候再次打开该窗口会显示异常
  205. _imageFile = @"C:\Users\dlrj\Desktop\晶粒度-冷轧薄板晶粒度评级2 - 副本.JPG";// openDialog.MSDialog.FileName;
  206. //_originalImage = Image.FromFile(_imageFile);
  207. InitializeComponent();
  208. InitializeLanguageText();
  209. //}
  210. //else
  211. //{
  212. // Dispose();
  213. //}
  214. }
  215. finally
  216. {
  217. //if (openDialog != null)
  218. // openDialog.Dispose();
  219. //openDialog = null;
  220. GC.Collect();
  221. GC.WaitForPendingFinalizers();
  222. }
  223. }
  224. else
  225. {
  226. InitializeComponent();
  227. InitializeLanguageText();
  228. }
  229. }
  230. private void MySaveDialogControl_Load(object sender, EventArgs e)
  231. {
  232. if (!DesignMode)
  233. {
  234. FileInfo fi = new FileInfo(_imageFile);
  235. }
  236. //if (_originalImage != null && !DesignMode)
  237. //{
  238. // //_pbOriginal.Image = _originalImage;
  239. // _format = _originalImage.RawFormat;
  240. // //_lblOrigInfo.Text = string.Format("Colors: {0}\nSize: {1} X {2} pixels\nHorizontal Resolution {3}\nVertical resolution: {4}",
  241. // // MyOpenFileDialogControl.GetColorsCountFromImage(_pbOriginal.Image), _originalImage.Width,
  242. // // _originalImage.Height, _originalImage.HorizontalResolution, _originalImage.VerticalResolution);
  243. // Display();
  244. //}
  245. }
  246. /// <summary>
  247. /// Clean up any resources being used.
  248. /// </summary>
  249. /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  250. protected override void Dispose(bool disposing)
  251. {
  252. if (_memstream != null)
  253. {
  254. _memstream.Dispose();
  255. _memstream = null;
  256. }
  257. if (disposing && (components != null))
  258. {
  259. components.Dispose();
  260. }
  261. base.Dispose(disposing);
  262. }
  263. private int GetIndexfromFile(string file)
  264. {
  265. try
  266. {
  267. string ext = System.IO.Path.GetExtension(file).ToLower();
  268. int index = MSDialog.Filter.ToLower().IndexOf(ext);
  269. string[] extensions = MSDialog.Filter.Substring(0, index).Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
  270. return extensions.Length / 2 + 1;
  271. }
  272. catch (Exception ex)
  273. {
  274. MessageBox.Show(this, ex.Message, "Unknown Format!", MessageBoxButtons.OK, MessageBoxIcon.Error);
  275. return 1;
  276. }
  277. }
  278. }
  279. }