📄 form1.cs
字号:
this.Zoom100.Text = "100%";
this.Zoom100.Click += new System.EventHandler(this.OnZoom100);
//
// Zoom150
//
this.Zoom150.Index = 3;
this.Zoom150.Text = "150%";
this.Zoom150.Click += new System.EventHandler(this.OnZoom150);
//
// Zoom200
//
this.Zoom200.Index = 4;
this.Zoom200.Text = "200%";
this.Zoom200.Click += new System.EventHandler(this.OnZoom200);
//
// Zoom300
//
this.Zoom300.Index = 5;
this.Zoom300.Text = "300%";
this.Zoom300.Click += new System.EventHandler(this.OnZoom300);
//
// Zoom500
//
this.Zoom500.Index = 6;
this.Zoom500.Text = "500%";
this.Zoom500.Click += new System.EventHandler(this.OnZoom500);
//
// FilterCustom
//
this.FilterCustom.Index = 6;
this.FilterCustom.Text = "Custom";
this.FilterCustom.Click += new System.EventHandler(this.OnFilterCustom);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.ClientSize = new System.Drawing.Size(488, 421);
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Graphic Filters For Dummies";
this.Load += new System.EventHandler(this.Form1_Load);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
protected override void OnPaint (PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawImage(m_Bitmap, new Rectangle(this.AutoScrollPosition.X, this.AutoScrollPosition.Y, (int)(m_Bitmap.Width*Zoom), (int)(m_Bitmap.Height * Zoom)));
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
private void File_Load(object sender, System.EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = "c:\\" ;
openFileDialog.Filter = "Bitmap files (*.bmp)|*.bmp|Jpeg files (*.jpg)|*.jpg|All valid files (*.bmp/*.jpg)|*.bmp/*.jpg";
openFileDialog.FilterIndex = 2 ;
openFileDialog.RestoreDirectory = true ;
if(DialogResult.OK == openFileDialog.ShowDialog())
{
m_Bitmap = (Bitmap)Bitmap.FromFile(openFileDialog.FileName, false);
this.AutoScroll = true;
this.AutoScrollMinSize = new Size ((int)(m_Bitmap.Width * Zoom), (int)(m_Bitmap.Height * Zoom));
this.Invalidate();
}
}
private void File_Save(object sender, System.EventArgs e)
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.InitialDirectory = "c:\\" ;
saveFileDialog.Filter = "Bitmap files (*.bmp)|*.bmp|Jpeg files (*.jpg)|*.jpg|All valid files (*.bmp/*.jpg)|*.bmp/*.jpg" ;
saveFileDialog.FilterIndex = 1 ;
saveFileDialog.RestoreDirectory = true ;
if(DialogResult.OK == saveFileDialog.ShowDialog())
{
m_Bitmap.Save(saveFileDialog.FileName);
}
}
private void File_Exit(object sender, System.EventArgs e)
{
this.Close();
}
private void Filter_Invert(object sender, System.EventArgs e)
{
m_Undo = (Bitmap)m_Bitmap.Clone();
if(BitmapFilter.Invert(m_Bitmap))
this.Invalidate();
}
private void Filter_GrayScale(object sender, System.EventArgs e)
{
m_Undo = (Bitmap)m_Bitmap.Clone();
if(BitmapFilter.GrayScale(m_Bitmap))
this.Invalidate();
}
private void Filter_Brightness(object sender, System.EventArgs e)
{
Parameter dlg = new Parameter();
dlg.nValue = 0;
if (DialogResult.OK == dlg.ShowDialog())
{
m_Undo = (Bitmap)m_Bitmap.Clone();
if(BitmapFilter.Brightness(m_Bitmap, dlg.nValue))
this.Invalidate();
}
}
private void Filter_Contrast(object sender, System.EventArgs e)
{
Parameter dlg = new Parameter();
dlg.nValue = 0;
if (DialogResult.OK == dlg.ShowDialog())
{
m_Undo = (Bitmap)m_Bitmap.Clone();
if(BitmapFilter.Contrast(m_Bitmap, (sbyte)dlg.nValue))
this.Invalidate();
}
}
private void Filter_Gamma(object sender, System.EventArgs e)
{
GammaInput dlg = new GammaInput();
dlg.red = dlg.green = dlg.blue = 1;
if (DialogResult.OK == dlg.ShowDialog())
{
m_Undo = (Bitmap)m_Bitmap.Clone();
if(BitmapFilter.Gamma(m_Bitmap, dlg.red, dlg.green, dlg.blue))
this.Invalidate();
}
}
private void Filter_Color(object sender, System.EventArgs e)
{
ColorInput dlg = new ColorInput();
dlg.red = dlg.green = dlg.blue = 0;
if (DialogResult.OK == dlg.ShowDialog())
{
m_Undo = (Bitmap)m_Bitmap.Clone();
if(BitmapFilter.Color(m_Bitmap, dlg.red, dlg.green, dlg.blue))
this.Invalidate();
}
}
private void OnZoom25(object sender, System.EventArgs e)
{
Zoom = .25;
this.AutoScrollMinSize = new Size ((int)(m_Bitmap.Width * Zoom), (int)(m_Bitmap.Height * Zoom));
this.Invalidate();
}
private void OnZoom50(object sender, System.EventArgs e)
{
Zoom = .5;
this.AutoScrollMinSize = new Size ((int)(m_Bitmap.Width * Zoom), (int)(m_Bitmap.Height * Zoom));
this.Invalidate();
}
private void OnZoom100(object sender, System.EventArgs e)
{
Zoom = 1.0;
this.AutoScrollMinSize = new Size ((int)(m_Bitmap.Width * Zoom), (int)(m_Bitmap.Height * Zoom));
this.Invalidate();
}
private void OnZoom150(object sender, System.EventArgs e)
{
Zoom = 1.5;
this.AutoScrollMinSize = new Size ((int)(m_Bitmap.Width * Zoom), (int)(m_Bitmap.Height * Zoom));
this.Invalidate();
}
private void OnZoom200(object sender, System.EventArgs e)
{
Zoom = 2.0;
this.AutoScrollMinSize = new Size ((int)(m_Bitmap.Width * Zoom), (int)(m_Bitmap.Height * Zoom));
this.Invalidate();
}
private void OnZoom300(object sender, System.EventArgs e)
{
Zoom = 3.0;
this.AutoScrollMinSize = new Size ((int)(m_Bitmap.Width * Zoom), (int)(m_Bitmap.Height * Zoom));
this.Invalidate();
}
private void OnZoom500(object sender, System.EventArgs e)
{
Zoom = 5;
this.AutoScrollMinSize = new Size ((int)(m_Bitmap.Width * Zoom), (int)(m_Bitmap.Height * Zoom));
this.Invalidate();
}
private void OnFilterSmooth(object sender, System.EventArgs e)
{
m_Undo = (Bitmap)m_Bitmap.Clone();
if(BitmapFilter.Smooth(m_Bitmap, 1))
this.Invalidate();
}
private void OnGaussianBlur(object sender, System.EventArgs e)
{
m_Undo = (Bitmap)m_Bitmap.Clone();
if(BitmapFilter.GaussianBlur(m_Bitmap, 4))
this.Invalidate();
}
private void OnMeanRemoval(object sender, System.EventArgs e)
{
m_Undo = (Bitmap)m_Bitmap.Clone();
if(BitmapFilter.MeanRemoval(m_Bitmap, 9))
this.Invalidate();
}
private void OnSharpen(object sender, System.EventArgs e)
{
m_Undo = (Bitmap)m_Bitmap.Clone();
if(BitmapFilter.Sharpen(m_Bitmap, 11))
this.Invalidate();
}
private void OnEmbossLaplacian(object sender, System.EventArgs e)
{
m_Undo = (Bitmap)m_Bitmap.Clone();
if(BitmapFilter.EmbossLaplacian(m_Bitmap))
this.Invalidate();
}
private void OnEdgeDetectQuick(object sender, System.EventArgs e)
{
m_Undo = (Bitmap)m_Bitmap.Clone();
if(BitmapFilter.EdgeDetectQuick(m_Bitmap))
this.Invalidate();
}
private void OnUndo(object sender, System.EventArgs e)
{
Bitmap temp = (Bitmap)m_Bitmap.Clone();
m_Bitmap = (Bitmap)m_Undo.Clone();
m_Undo = (Bitmap)temp.Clone();
this.Invalidate();
}
private void OnFilterCustom(object sender, System.EventArgs e)
{
Convolution dlg = new Convolution();
if (DialogResult.OK == dlg.ShowDialog())
{
m_Undo = (Bitmap)m_Bitmap.Clone();
if(BitmapFilter.Conv3x3(m_Bitmap, dlg.Matrix))
this.Invalidate();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -