using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.IO;
using PaintDotNet.SystemLayer.FileDlgExtenders.FileDialogExtenders;
namespace PaintDotNet.File
{
public partial class MySaveDialogControl : FileDialogControlBase
{
///
/// 必需的设计器变量。
///
private System.ComponentModel.IContainer components = null;
#region 组件设计器生成的代码
private void InitializeLanguageText()
{
this.checkBox5.Text = PdnResources.GetString("Menu.Compressionratio.text");
this.checkBox4.Text = PdnResources.GetString("Menu.Annotationandmddedintheimage.text");
this.checkBox3.Text = PdnResources.GetString("Menu.Savegriddata.text");
this.checkBox2.Text = PdnResources.GetString("Menu.Closeimageaftersaving.text");
this.checkBox1.Text = PdnResources.GetString("Menu.Generateconfigurationfile.text");
this.FileDlgCaption = PdnResources.GetString("Menu.file.Saveall.Savetheimagefileas.text");
}
///
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
///
private void InitializeComponent()
{
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
this.checkBox5 = new System.Windows.Forms.CheckBox();
this.checkBox4 = new System.Windows.Forms.CheckBox();
this.checkBox3 = new System.Windows.Forms.CheckBox();
this.checkBox2 = new System.Windows.Forms.CheckBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.label1 = new System.Windows.Forms.Label();
this.checkBox6 = new System.Windows.Forms.CheckBox();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
this.SuspendLayout();
//
// numericUpDown1
//
this.numericUpDown1.Location = new System.Drawing.Point(176, 59);
this.numericUpDown1.Margin = new System.Windows.Forms.Padding(2);
this.numericUpDown1.Name = "numericUpDown1";
this.numericUpDown1.Size = new System.Drawing.Size(41, 21);
this.numericUpDown1.TabIndex = 15;
//
// checkBox5
//
this.checkBox5.AutoSize = true;
this.checkBox5.Location = new System.Drawing.Point(103, 62);
this.checkBox5.Margin = new System.Windows.Forms.Padding(2);
this.checkBox5.Name = "checkBox5";
this.checkBox5.Size = new System.Drawing.Size(72, 16);
this.checkBox5.TabIndex = 14;
this.checkBox5.Text = "压缩比例";
this.checkBox5.UseVisualStyleBackColor = true;
//
// checkBox4
//
this.checkBox4.AutoSize = true;
this.checkBox4.Location = new System.Drawing.Point(290, 36);
this.checkBox4.Margin = new System.Windows.Forms.Padding(2);
this.checkBox4.Name = "checkBox4";
this.checkBox4.Size = new System.Drawing.Size(156, 16);
this.checkBox4.TabIndex = 13;
this.checkBox4.Text = "标注和测量信息嵌入图像";
this.checkBox4.UseVisualStyleBackColor = true;
//
// checkBox3
//
this.checkBox3.AutoSize = true;
this.checkBox3.Location = new System.Drawing.Point(103, 36);
this.checkBox3.Margin = new System.Windows.Forms.Padding(2);
this.checkBox3.Name = "checkBox3";
this.checkBox3.Size = new System.Drawing.Size(96, 16);
this.checkBox3.TabIndex = 12;
this.checkBox3.Text = "保存网格数据";
this.checkBox3.UseVisualStyleBackColor = true;
//
// checkBox2
//
this.checkBox2.AutoSize = true;
this.checkBox2.Checked = true;
this.checkBox2.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBox2.Location = new System.Drawing.Point(290, 10);
this.checkBox2.Margin = new System.Windows.Forms.Padding(2);
this.checkBox2.Name = "checkBox2";
this.checkBox2.Size = new System.Drawing.Size(108, 16);
this.checkBox2.TabIndex = 11;
this.checkBox2.Text = "保存后关闭图像";
this.checkBox2.UseVisualStyleBackColor = true;
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Checked = true;
this.checkBox1.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBox1.Location = new System.Drawing.Point(103, 10);
this.checkBox1.Margin = new System.Windows.Forms.Padding(2);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(96, 16);
this.checkBox1.TabIndex = 10;
this.checkBox1.Text = "生成配置文件";
this.checkBox1.UseVisualStyleBackColor = true;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("宋体", 12F);
this.label1.Location = new System.Drawing.Point(220, 61);
this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(16, 16);
this.label1.TabIndex = 16;
this.label1.Text = "%";
//
// checkBox6
//
this.checkBox6.AutoSize = true;
this.checkBox6.Location = new System.Drawing.Point(290, 62);
this.checkBox6.Name = "checkBox6";
this.checkBox6.Size = new System.Drawing.Size(108, 16);
this.checkBox6.TabIndex = 17;
this.checkBox6.Text = "相信息嵌入图像";
this.checkBox6.UseVisualStyleBackColor = true;
//
// MySaveDialogControl
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.checkBox6);
this.Controls.Add(this.label1);
this.Controls.Add(this.numericUpDown1);
this.Controls.Add(this.checkBox5);
this.Controls.Add(this.checkBox4);
this.Controls.Add(this.checkBox3);
this.Controls.Add(this.checkBox2);
this.Controls.Add(this.checkBox1);
this.FileDlgCaption = "保存图像文件为";
this.FileDlgStartLocation = PaintDotNet.SystemLayer.FileDlgExtenders.FileDialogExtenders.AddonWindowLocation.Bottom;
this.Margin = new System.Windows.Forms.Padding(2);
this.Name = "MySaveDialogControl";
this.Size = new System.Drawing.Size(524, 101);
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
ImageFormat _format = ImageFormat.Jpeg;
System.IO.MemoryStream _memstream;
public NumericUpDown numericUpDown1;
public CheckBox checkBox5;
public CheckBox checkBox4;
public CheckBox checkBox3;
public CheckBox checkBox2;
public CheckBox checkBox1;
public Label label1;
public CheckBox checkBox6;
string _imageFile;
public MySaveDialogControl()
{
InitializeComponent();
InitializeLanguageText();
}
protected override void OnPrepareMSDialog()
{
base.OnPrepareMSDialog();
MSDialog.FilterIndex = GetIndexfromFile(_imageFile);
if (Environment.OSVersion.Version.Major < 6)
MSDialog.SetPlaces(new object[] { (int)Places.Desktop, (int)Places.Printers, (int)Places.Favorites, (int)Places.Programs, (int)Places.Fonts, });
FileDlgInitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
}
public MySaveDialogControl(string originalfile, IWin32Window parent)
{
try
{
_imageFile = originalfile;
//_originalImage = Image.FromFile(originalfile);
}
catch
{
_imageFile = null;
}
if (_imageFile == null || _imageFile.Length == 0)
{
//MyOpenFileDialogControl openDialog = new MyOpenFileDialogControl();
//openDialog.FileDlgCheckFileExists = false;
try
{
//if (parent == null)
// parent = Application.OpenForms[0];
//if (openDialog.ShowDialog(parent) == DialogResult.OK)
//{
//备注:这里处理保存按钮的点击事件
//备注:下一个问题:为什么路径存在图片时候再次打开该窗口会显示异常
_imageFile = @"C:\Users\dlrj\Desktop\晶粒度-冷轧薄板晶粒度评级2 - 副本.JPG";// openDialog.MSDialog.FileName;
//_originalImage = Image.FromFile(_imageFile);
InitializeComponent();
InitializeLanguageText();
//}
//else
//{
// Dispose();
//}
}
finally
{
//if (openDialog != null)
// openDialog.Dispose();
//openDialog = null;
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
else
{
InitializeComponent();
InitializeLanguageText();
}
}
private void MySaveDialogControl_Load(object sender, EventArgs e)
{
if (!DesignMode)
{
FileInfo fi = new FileInfo(_imageFile);
}
//if (_originalImage != null && !DesignMode)
//{
// //_pbOriginal.Image = _originalImage;
// _format = _originalImage.RawFormat;
// //_lblOrigInfo.Text = string.Format("Colors: {0}\nSize: {1} X {2} pixels\nHorizontal Resolution {3}\nVertical resolution: {4}",
// // MyOpenFileDialogControl.GetColorsCountFromImage(_pbOriginal.Image), _originalImage.Width,
// // _originalImage.Height, _originalImage.HorizontalResolution, _originalImage.VerticalResolution);
// Display();
//}
}
///
/// Clean up any resources being used.
///
/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (_memstream != null)
{
_memstream.Dispose();
_memstream = null;
}
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private int GetIndexfromFile(string file)
{
try
{
string ext = System.IO.Path.GetExtension(file).ToLower();
int index = MSDialog.Filter.ToLower().IndexOf(ext);
string[] extensions = MSDialog.Filter.Substring(0, index).Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
return extensions.Length / 2 + 1;
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message, "Unknown Format!", MessageBoxButtons.OK, MessageBoxIcon.Error);
return 1;
}
}
}
}