private void button1_Click(object sender, System.EventArgs e)
{
Bitmap bmp = new Bitmap (this.pictureBox1.Image);
frmExportBitmap fep = new frmExportBitmap (bmp);
fep.ShowDialog();
}
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing.Imaging;
namespace WindowsApplication2
{
///
/// Summary description for frmExportBitmap.
///
public class frmExportBitmap : System.Windows.Forms.Form
{
#region Housekeeping
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Panel panelBottom;
private System.Windows.Forms.Button buttonExport;
private System.Windows.Forms.Button button1;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
#endregion
private System.Windows.Forms.Label labelHRes;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.GroupBox groupBoxInfo;
private System.Windows.Forms.GroupBox groupBoxPreview;
private System.Windows.Forms.GroupBox groupBoxExportFormat;
private System.Windows.Forms.RadioButton radioButtonBMP;
private System.Windows.Forms.RadioButton radioButtonJPEG;
private System.Windows.Forms.Panel panelExport;
private System.Windows.Forms.Label labelHeight;
private System.Windows.Forms.Label labelWidth;
private System.Windows.Forms.TrackBar trackBar1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label labelQuality;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.RadioButton radioButtonColor;
private System.Windows.Forms.RadioButton radioButtonGS;
private System.Windows.Forms.CheckBox checkBoxOpen;
private System.Windows.Forms.Label label22;
private System.Windows.Forms.Label labelVRes;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.PictureBox pictureBox1;
#region Locals
private Bitmap _bmp;
#endregion
#region Ctor/Dtor
public frmExportBitmap(Bitmap bmp)
{
InitializeComponent();
this._bmp = bmp;
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#endregion
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.labelHeight = new System.Windows.Forms.Label();
this.labelWidth = new System.Windows.Forms.Label();
this.panelBottom = new System.Windows.Forms.Panel();
this.button1 = new System.Windows.Forms.Button();
this.buttonExport = new System.Windows.Forms.Button();
this.checkBoxOpen = new System.Windows.Forms.CheckBox();
this.groupBoxInfo = new System.Windows.Forms.GroupBox();
this.label22 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.labelVRes = new System.Windows.Forms.Label();
this.labelHRes = new System.Windows.Forms.Label();
this.groupBoxPreview = new System.Windows.Forms.GroupBox();
this.groupBoxExportFormat = new System.Windows.Forms.GroupBox();
this.panel1 = new System.Windows.Forms.Panel();
this.trackBar1 = new System.Windows.Forms.TrackBar();
this.label7 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.labelQuality = new System.Windows.Forms.Label();
this.radioButtonJPEG = new System.Windows.Forms.RadioButton();
this.radioButtonBMP = new System.Windows.Forms.RadioButton();
this.panelExport = new System.Windows.Forms.Panel();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.radioButtonColor = new System.Windows.Forms.RadioButton();
this.radioButtonGS = new System.Windows.Forms.RadioButton();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.panelBottom.SuspendLayout();
this.groupBoxInfo.SuspendLayout();
this.groupBoxPreview.SuspendLayout();
this.groupBoxExportFormat.SuspendLayout();
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();
this.panelExport.SuspendLayout();
this.groupBox2.SuspendLayout();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// label1
//
this.label1.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label1.Location = new System.Drawing.Point(8, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(48, 16);
this.label1.TabIndex = 0;
this.label1.Text = "Height:";
//
// label2
//
this.label2.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label2.Location = new System.Drawing.Point(8, 40);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(40, 16);
this.label2.TabIndex = 1;
this.label2.Text = "Width:";
//
// labelHeight
//
this.labelHeight.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.labelHeight.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.labelHeight.Location = new System.Drawing.Point(56, 24);
this.labelHeight.Name = "labelHeight";
this.labelHeight.Size = new System.Drawing.Size(64, 16);
this.labelHeight.TabIndex = 2;
//
// labelWidth
//
this.labelWidth.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.labelWidth.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.labelWidth.Location = new System.Drawing.Point(56, 40);
this.labelWidth.Name = "labelWidth";
this.labelWidth.Size = new System.Drawing.Size(64, 16);
this.labelWidth.TabIndex = 3;
//
// panelBottom
//
this.panelBottom.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panelBottom.Controls.Add(this.button1);
this.panelBottom.Controls.Add(this.buttonExport);
this.panelBottom.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panelBottom.Location = new System.Drawing.Point(0, 374);
this.panelBottom.Name = "panelBottom";
this.panelBottom.Size = new System.Drawing.Size(616, 32);
this.panelBottom.TabIndex = 5;
//
// button1
//
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.button1.Location = new System.Drawing.Point(526, 5);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(84, 21);
this.button1.TabIndex = 1;
this.button1.Text = "Cancel";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// buttonExport
//
this.buttonExport.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonExport.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.buttonExport.Location = new System.Drawing.Point(438, 5);
this.buttonExport.Name = "buttonExport";
this.buttonExport.Size = new System.Drawing.Size(84, 21);
this.buttonExport.TabIndex = 0;
this.buttonExport.Text = "Export";
this.buttonExport.Click += new System.EventHandler(this.buttonExport_Click);
//
// checkBoxOpen
//
this.checkBoxOpen.Checked = true;
this.checkBoxOpen.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBoxOpen.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.checkBoxOpen.Location = new System.Drawing.Point(8, 24);
this.checkBoxOpen.Name = "checkBoxOpen";
this.checkBoxOpen.Size = new System.Drawing.Size(184, 16);
this.checkBoxOpen.TabIndex = 2;
this.checkBoxOpen.Text = "Open Picture after Export";
//
// groupBoxInfo
//
this.groupBoxInfo.Controls.Add(this.label22);
this.groupBoxInfo.Controls.Add(this.label5);
this.groupBoxInfo.Controls.Add(this.label2);
this.groupBoxInfo.Controls.Add(this.labelVRes);
this.groupBoxInfo.Controls.Add(this.labelHRes);
this.groupBoxInfo.Controls.Add(this.labelHeight);
this.groupBoxInfo.Controls.Add(this.labelWidth);
this.groupBoxInfo.Controls.Add(this.label1);
this.groupBoxInfo.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.groupBoxInfo.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.groupBoxInfo.Location = new System.Drawing.Point(8, 0);
this.groupBoxInfo.Name = "groupBoxInfo";
this.groupBoxInfo.Size = new System.Drawing.Size(216, 96);
this.groupBoxInfo.TabIndex = 9;
this.groupBoxInfo.TabStop = false;
this.groupBoxInfo.Text = "Image Information";
//
// label22
//
this.label22.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label22.Location = new System.Drawing.Point(8, 72);
this.label22.Name = "label22";
this.label22.Size = new System.Drawing.Size(48, 16);
this.label22.TabIndex = 6;
this.label22.Text = "V Res:";
//
// label5
//
this.label5.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label5.Location = new System.Drawing.Point(8, 56);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(40, 16);
this.label5.TabIndex = 4;
this.label5.Text = "H Res:";
//
// labelVRes
//
this.labelVRes.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.labelVRes.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.labelVRes.Location = new System.Drawing.Point(56, 72);
this.labelVRes.Name = "labelVRes";
this.labelVRes.Size = new System.Drawing.Size(64, 16);
this.labelVRes.TabIndex = 7;
//
// labelHRes
//
this.labelHRes.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.labelHRes.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.labelHRes.Location = new System.Drawing.Point(56, 56);
this.labelHRes.Name = "labelHRes";
this.labelHRes.Size = new System.Drawing.Size(64, 16);
this.labelHRes.TabIndex = 5;
//
// groupBoxPreview
//
this.groupBoxPreview.Controls.Add(this.pictureBox1);
this.groupBoxPreview.Dock = System.Windows.Forms.DockStyle.Fill;
this.groupBoxPreview.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.groupBoxPreview.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.groupBoxPreview.Location = new System.Drawing.Point(0, 0);
this.groupBoxPreview.Name = "groupBoxPreview";
this.groupBoxPreview.Size = new System.Drawing.Size(384, 374);
this.groupBoxPreview.TabIndex = 10;
this.groupBoxPreview.TabStop = false;
this.groupBoxPreview.Text = "Preview";
//
// groupBoxExportFormat
//
this.groupBoxExportFormat.Controls.Add(this.panel1);
this.groupBoxExportFormat.Controls.Add(this.radioButtonJPEG);
this.groupBoxExportFormat.Controls.Add(this.radioButtonBMP);
this.groupBoxExportFormat.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.groupBoxExportFormat.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.groupBoxExportFormat.Location = new System.Drawing.Point(8, 104);
this.groupBoxExportFormat.Name = "groupBoxExportFormat";
this.groupBoxExportFormat.Size = new System.Drawing.Size(216, 133);
this.groupBoxExportFormat.TabIndex = 11;
this.groupBoxExportFormat.TabStop = false;
this.groupBoxExportFormat.Text = "Export Format";
//
// panel1
//
this.panel1.Controls.Add(this.trackBar1);
this.panel1.Controls.Add(this.label7);
this.panel1.Controls.Add(this.label3);
this.panel1.Controls.Add(this.label4);
this.panel1.Controls.Add(this.labelQuality);
this.panel1.Location = new System.Drawing.Point(8, 40);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(198, 64);
this.panel1.TabIndex = 12;
//
// trackBar1
//
this.trackBar1.AutoSize = false;
this.trackBar1.Location = new System.Drawing.Point(8, 38);
this.trackBar1.Maximum = 100;
this.trackBar1.Name = "trackBar1";
this.trackBar1.Size = new System.Drawing.Size(185, 20);
this.trackBar1.TabIndex = 9;
this.trackBar1.TickFrequency = 10;
this.trackBar1.Value = 85;
this.trackBar1.ValueChanged += new System.EventHandler(this.trackBar1_ValueChanged);
//
// label7
//
this.label7.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label7.Location = new System.Drawing.Point(14, 5);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(120, 17);
this.label7.TabIndex = 1;
this.label7.Text = "Quality/Compression:";
//
// label3
//
this.label3.Font = new System.Drawing.Font("Tahoma", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label3.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
this.label3.Location = new System.Drawing.Point(102, 16);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(87, 32);
this.label3.TabIndex = 10;
this.label3.Text = "Highest Quality >>";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label4
//
this.label4.Font = new System.Drawing.Font("Tahoma", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label4.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(0)), ((System.Byte)(192)));
this.label4.Location = new System.Drawing.Point(11, 16);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(90, 32);
this.label4.TabIndex = 11;
this.label4.Text = "<< Smallest Size";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// labelQuality
//
this.labelQuality.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.labelQuality.Location = new System.Drawing.Point(126, 5);
this.labelQuality.Name = "labelQuality";
this.labelQuality.Size = new System.Drawing.Size(51, 16);
this.labelQuality.TabIndex = 3;
//
// radioButtonJPEG
//
this.radioButtonJPEG.Checked = true;
this.radioButtonJPEG.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.radioButtonJPEG.Location = new System.Drawing.Point(8, 24);
this.radioButtonJPEG.Name = "radioButtonJPEG";
this.radioButtonJPEG.Size = new System.Drawing.Size(120, 24);
this.radioButtonJPEG.TabIndex = 8;
this.radioButtonJPEG.TabStop = true;
this.radioButtonJPEG.Text = "Compressed (JPEG)";
//
// radioButtonBMP
//
this.radioButtonBMP.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.radioButtonBMP.Location = new System.Drawing.Point(8, 110);
this.radioButtonBMP.Name = "radioButtonBMP";
this.radioButtonBMP.Size = new System.Drawing.Size(197, 18);
this.radioButtonBMP.TabIndex = 7;
this.radioButtonBMP.Text = "Uncompressed (Windows Bitmap)";
//
// panelExport
//
this.panelExport.Controls.Add(this.groupBox2);
this.panelExport.Controls.Add(this.groupBox1);
this.panelExport.Controls.Add(this.groupBoxExportFormat);
this.panelExport.Controls.Add(this.groupBoxInfo);
this.panelExport.Dock = System.Windows.Forms.DockStyle.Right;
this.panelExport.Location = new System.Drawing.Point(384, 0);
this.panelExport.Name = "panelExport";
this.panelExport.Size = new System.Drawing.Size(232, 374);
this.panelExport.TabIndex = 12;
//
// groupBox2
//
this.groupBox2.Controls.Add(this.checkBoxOpen);
this.groupBox2.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.groupBox2.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.groupBox2.Location = new System.Drawing.Point(8, 320);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(216, 48);
this.groupBox2.TabIndex = 13;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Options";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.radioButtonColor);
this.groupBox1.Controls.Add(this.radioButtonGS);
this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.groupBox1.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.groupBox1.Location = new System.Drawing.Point(8, 248);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(216, 64);
this.groupBox1.TabIndex = 12;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Color Format";
//
// radioButtonColor
//
this.radioButtonColor.Checked = true;
this.radioButtonColor.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.radioButtonColor.Location = new System.Drawing.Point(8, 16);
this.radioButtonColor.Name = "radioButtonColor";
this.radioButtonColor.Size = new System.Drawing.Size(72, 24);
this.radioButtonColor.TabIndex = 8;
this.radioButtonColor.TabStop = true;
this.radioButtonColor.Text = "Color";
//
// radioButtonGS
//
this.radioButtonGS.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.radioButtonGS.Location = new System.Drawing.Point(8, 40);
this.radioButtonGS.Name = "radioButtonGS";
this.radioButtonGS.Size = new System.Drawing.Size(88, 21);
this.radioButtonGS.TabIndex = 7;
this.radioButtonGS.Text = "Grayscale";
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(8, 24);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(368, 344);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// frmExportBitmap
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
this.BackColor = System.Drawing.Color.WhiteSmoke;
this.ClientSize = new System.Drawing.Size(616, 406);
this.Controls.Add(this.groupBoxPreview);
this.Controls.Add(this.panelExport);
this.Controls.Add(this.panelBottom);
this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size(504, 416);
this.Name = "frmExportBitmap";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Export as Picture";
this.Load += new System.EventHandler(this.frmExportBitmap_Load);
this.panelBottom.ResumeLayout(false);
this.groupBoxInfo.ResumeLayout(false);
this.groupBoxPreview.ResumeLayout(false);
this.groupBoxExportFormat.ResumeLayout(false);
this.panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
this.panelExport.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
#region Methods
#endregion
private void frmExportBitmap_Load(object sender, System.EventArgs e)
{
this.pictureBox1.Image = this._bmp;
this.labelQuality.Text = this.trackBar1.Value.ToString();
this.labelHeight.Text = this._bmp.Size.Height.ToString();
this.labelWidth.Text = this._bmp.Size.Height.ToString();
this.labelHRes.Text = _bmp.HorizontalResolution.ToString();
this.labelVRes.Text = _bmp.VerticalResolution.ToString();
}
private void SaveJPEG(Bitmap theBitMap, string filename)
{
ImageCodecInfo myImageCodecInfo;
Encoder myEncoder;
EncoderParameter myEncoderParameter;
EncoderParameters myEncoderParameters;
myImageCodecInfo = GetEncoderInfo("image/jpeg");
myEncoder = Encoder.Quality;
myEncoderParameters = new EncoderParameters(1);
myEncoderParameter = new EncoderParameter(myEncoder, this.trackBar1.Value);
myEncoderParameters.Param[0] = myEncoderParameter;
theBitMap.Save(filename, myImageCodecInfo, myEncoderParameters);
}
private void SaveBMP (Bitmap theBitMap, string filename)
{
theBitMap.Save (filename);
}
private void buttonExport_Click(object sender, System.EventArgs e)
{
string filename = String.Empty;
string mask = String.Empty;
SaveFileDialog sfd = new SaveFileDialog();
sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
sfd.Title = "Save Picture";
if (this.radioButtonBMP.Checked)
{
mask = "Bitmap File (*.bmp)|*.bmp";
filename = "Exported.bmp";
}
else
{
mask = "JPEG File (*.JPEG)|*.JPEG";
filename = "Exported.JPEG";
}
sfd.FileName = filename;
sfd.Filter = mask;
DialogResult dr = sfd.ShowDialog();
if (dr == DialogResult.OK)
{
Bitmap theBitMap;
if (this.radioButtonGS.Checked)
{
theBitMap = this.ConvertAverageMatrix (_bmp);
}
else
{
theBitMap = this._bmp;
}
if (this.radioButtonBMP.Checked)
{
SaveBMP (theBitMap, sfd.FileName);
}
else
{
SaveJPEG (theBitMap, sfd.FileName);
}
}
sfd.Dispose();
if (this.checkBoxOpen.Checked)
{
System.Diagnostics.Process.Start (filename);
}
}
private System.Drawing.Bitmap ConvertAverageMatrix(System.Drawing.Bitmap BitmapIn)
{
Bitmap newB = (Bitmap)BitmapIn.Clone();
System.Drawing.Rectangle
bounds = new System.Drawing.Rectangle(0,0,newB.Width, newB.Height);
System.Drawing.Imaging.ColorMatrix
matrix = new System.Drawing.Imaging.ColorMatrix();
matrix[0,0] = 1/3f;
matrix[0,1] = 1/3f;
matrix[0,2] = 1/3f;
matrix[1,0] = 1/3f;
matrix[1,1] = 1/3f;
matrix[1,2] = 1/3f;
matrix[2,0] = 1/3f;
matrix[2,1] = 1/3f;
matrix[2,2] = 1/3f;
System.Drawing.Imaging.ImageAttributes
attributes = new System.Drawing.Imaging.ImageAttributes();
attributes.SetColorMatrix(matrix);
System.Drawing.Graphics
graphics = System.Drawing.Graphics.FromImage(newB);
graphics.DrawImage(newB, bounds, 0, 0, newB.Width, newB.Height, System.Drawing.GraphicsUnit.Pixel, attributes);
graphics.Dispose();
return newB;
}
private static ImageCodecInfo GetEncoderInfo(String mimeType)
{
int j;
ImageCodecInfo[] encoders;
encoders = ImageCodecInfo.GetImageEncoders();
for(j = 0; j < encoders.Length; ++j)
{
if(encoders[j].MimeType == mimeType)
return encoders[j];
}
return null;
}
private void trackBar1_ValueChanged(object sender, System.EventArgs e)
{
this.labelQuality.Text = trackBar1.Value.ToString();
}
private void button1_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}