MySaveDialogControl.cs 10 KB

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