有这么一段代码
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms; namespace PicsTransform
{
/// <summary>
/// 图像变换程序的主窗体,接受其子窗体的设置信息。
/// </summary>
public class MainForm : Form
{
private MainMenu mainMenu;
private MenuItem File;
private MenuItem OpenPics;
private MenuItem Transform;
private MenuItem x_Transform;
private PictureBox pictureBox;
private OpenFileDialog openFileDialog;
private MenuItem SizeChange;
private MenuItem PicsCircumrotate;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private Container components = null; public MainForm()
{ InitializeComponent(); } protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码 private void InitializeComponent()
{
this.mainMenu = new MainMenu();
this.File = new MenuItem();
this.OpenPics = new MenuItem();
this.Transform = new MenuItem();
this.x_Transform = new MenuItem();
this.SizeChange = new MenuItem();
this.pictureBox = new PictureBox();
this.openFileDialog = new OpenFileDialog();
this.PicsCircumrotate = new MenuItem();
this.SuspendLayout(); this.mainMenu.MenuItems.AddRange(new MenuItem[] {
this.File,
this.Transform});
this.File.Index = 0;
this.File.MenuItems.AddRange(new MenuItem[] {
this.OpenPics});
this.File.Text = "文件"; this.OpenPics.Index = 0;
this.OpenPics.Text = "打开";
this.OpenPics.Click += new EventHandler(this.OpenPics_Click);
this.Transform.Index = 1;
this.Transform.MenuItems.AddRange(new MenuItem[] {
this.x_Transform,
this.SizeChange,
this.PicsCircumrotate});
this.Transform.Text = "图像变换";
this.x_Transform.Index = 0;
this.x_Transform.Text = "图像平移";
this.x_Transform.Click += new EventHandler(this.x_Transform_Click); this.SizeChange.Index = 1;
this.SizeChange.Text = "图像缩放";
this.SizeChange.Click += new EventHandler(this.SizeChange_Click);
this.pictureBox.Location = new Point(0, 0);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new Size(584, 374);
this.pictureBox.SizeMode = PictureBoxSizeMode.AutoSize;
this.pictureBox.TabIndex = 0;
this.pictureBox.TabStop = false;
this.PicsCircumrotate.Index = 2;
this.PicsCircumrotate.Text = "图像旋转";
this.PicsCircumrotate.Click += new EventHandler(this.PicsCircumrotate_Click);
this.AutoScaleBaseSize = new Size(6, 14);
this.AutoScroll = true;
this.ClientSize = new Size(584, 374);
this.Controls.Add(this.pictureBox);
this.Menu = this.mainMenu;
this.Name = "MainForm";
this.Text = "图像变换";
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new MainForm());
}
/// <summary>
/// 打开一个图像文件(在此不是显式存储为数组)
/// </summary>
Bitmap bmp;
private void OpenPics_Click(object sender, EventArgs e)
{
if (this.openFileDialog.ShowDialog()==DialogResult.OK)
{
bmp=new Bitmap(this.openFileDialog.FileName);
this.pictureBox.Image=bmp;
}
}
/// <summary>
/// 图像平面移动处理事件
/// </summary>
float x=0,y=0;
private void x_Transform_Click(object sender, EventArgs e)
{
Getx_y answindow = new Getx_y();
if(answindow.ShowDialog(this)==DialogResult.OK) //接受可变数值
{
x += (float)Double.Parse(answindow.textBox_x.Text);
y += (float)Double.Parse(answindow.textBox_y.Text);
//We would apply
}
answindow.Dispose();
Bitmap final = new Bitmap(bmp.Width+(int)x,bmp.Height+(int)y ,pictureBox.CreateGraphics());//对图像数组进行扩充
Graphics g = Graphics.FromImage(final);
Point poi =new Point(0,0);
Size siz = new Size(bmp.Width,bmp.Height);
Rectangle r = new Rectangle(poi,siz);
r = new Rectangle(poi,siz);
g.TranslateTransform(x,y);//对增广数组进行平移
g.DrawImage(bmp,r);
this.pictureBox.Image = final;
}
/// <summary>
/// 图像缩放处理事件
/// </summary>
float changesize_x = 0,changesize_y=0;//缩放方向参数
private void SizeChange_Click(object sender, EventArgs e)
{
SizeChange answindow = new SizeChange();
if(answindow.ShowDialog(this)==DialogResult.OK)
{
changesize_x += (float)Double.Parse(answindow.x_Size.Text);
changesize_y += (float)Double.Parse(answindow.y_Size.Text);
//We would apply
}
answindow.Dispose();
float bmp_x = (float)bmp.Width*changesize_x;
float bmp_y = (float)bmp.Height*changesize_y;
Bitmap final = new Bitmap((int)bmp_x,(int)bmp_y ,pictureBox.CreateGraphics());//扩充图像原来的数组
Graphics g = Graphics.FromImage(final);
Point poi =new Point(0,0);
Size siz = new Size(bmp.Width,bmp.Height);
this.Text=bmp.Width.ToString();
Rectangle r = new Rectangle(poi,siz);
this.Text=siz.Height.ToString(); r = new Rectangle(poi,siz);
g.ScaleTransform(changesize_x,changesize_y);//进行缩放重绘
g.DrawImage(bmp,r);
this.pictureBox.Image = final;
}
/// <summary>
/// 图象旋转处理事件
/// </summary>
float rotatearc = 0;//选择顺时针旋转角度(最好为0-90度,选择其他角度会有图像越界)
private void PicsCircumrotate_Click(object sender, EventArgs e)
{
Circumrotate answindow = new Circumrotate();
if(answindow.ShowDialog(this)==DialogResult.OK)
{
rotatearc += (float)Double.Parse(answindow.arc.Text);
}
answindow.Dispose();
} }
} 我运行了,但总提示Getx_y ,SizeChange ,Circumrotate 出错,找不到。 是怎么回事呢。望高手指点
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms; namespace PicsTransform
{
/// <summary>
/// 图像变换程序的主窗体,接受其子窗体的设置信息。
/// </summary>
public class MainForm : Form
{
private MainMenu mainMenu;
private MenuItem File;
private MenuItem OpenPics;
private MenuItem Transform;
private MenuItem x_Transform;
private PictureBox pictureBox;
private OpenFileDialog openFileDialog;
private MenuItem SizeChange;
private MenuItem PicsCircumrotate;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private Container components = null; public MainForm()
{ InitializeComponent(); } protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码 private void InitializeComponent()
{
this.mainMenu = new MainMenu();
this.File = new MenuItem();
this.OpenPics = new MenuItem();
this.Transform = new MenuItem();
this.x_Transform = new MenuItem();
this.SizeChange = new MenuItem();
this.pictureBox = new PictureBox();
this.openFileDialog = new OpenFileDialog();
this.PicsCircumrotate = new MenuItem();
this.SuspendLayout(); this.mainMenu.MenuItems.AddRange(new MenuItem[] {
this.File,
this.Transform});
this.File.Index = 0;
this.File.MenuItems.AddRange(new MenuItem[] {
this.OpenPics});
this.File.Text = "文件"; this.OpenPics.Index = 0;
this.OpenPics.Text = "打开";
this.OpenPics.Click += new EventHandler(this.OpenPics_Click);
this.Transform.Index = 1;
this.Transform.MenuItems.AddRange(new MenuItem[] {
this.x_Transform,
this.SizeChange,
this.PicsCircumrotate});
this.Transform.Text = "图像变换";
this.x_Transform.Index = 0;
this.x_Transform.Text = "图像平移";
this.x_Transform.Click += new EventHandler(this.x_Transform_Click); this.SizeChange.Index = 1;
this.SizeChange.Text = "图像缩放";
this.SizeChange.Click += new EventHandler(this.SizeChange_Click);
this.pictureBox.Location = new Point(0, 0);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new Size(584, 374);
this.pictureBox.SizeMode = PictureBoxSizeMode.AutoSize;
this.pictureBox.TabIndex = 0;
this.pictureBox.TabStop = false;
this.PicsCircumrotate.Index = 2;
this.PicsCircumrotate.Text = "图像旋转";
this.PicsCircumrotate.Click += new EventHandler(this.PicsCircumrotate_Click);
this.AutoScaleBaseSize = new Size(6, 14);
this.AutoScroll = true;
this.ClientSize = new Size(584, 374);
this.Controls.Add(this.pictureBox);
this.Menu = this.mainMenu;
this.Name = "MainForm";
this.Text = "图像变换";
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new MainForm());
}
/// <summary>
/// 打开一个图像文件(在此不是显式存储为数组)
/// </summary>
Bitmap bmp;
private void OpenPics_Click(object sender, EventArgs e)
{
if (this.openFileDialog.ShowDialog()==DialogResult.OK)
{
bmp=new Bitmap(this.openFileDialog.FileName);
this.pictureBox.Image=bmp;
}
}
/// <summary>
/// 图像平面移动处理事件
/// </summary>
float x=0,y=0;
private void x_Transform_Click(object sender, EventArgs e)
{
Getx_y answindow = new Getx_y();
if(answindow.ShowDialog(this)==DialogResult.OK) //接受可变数值
{
x += (float)Double.Parse(answindow.textBox_x.Text);
y += (float)Double.Parse(answindow.textBox_y.Text);
//We would apply
}
answindow.Dispose();
Bitmap final = new Bitmap(bmp.Width+(int)x,bmp.Height+(int)y ,pictureBox.CreateGraphics());//对图像数组进行扩充
Graphics g = Graphics.FromImage(final);
Point poi =new Point(0,0);
Size siz = new Size(bmp.Width,bmp.Height);
Rectangle r = new Rectangle(poi,siz);
r = new Rectangle(poi,siz);
g.TranslateTransform(x,y);//对增广数组进行平移
g.DrawImage(bmp,r);
this.pictureBox.Image = final;
}
/// <summary>
/// 图像缩放处理事件
/// </summary>
float changesize_x = 0,changesize_y=0;//缩放方向参数
private void SizeChange_Click(object sender, EventArgs e)
{
SizeChange answindow = new SizeChange();
if(answindow.ShowDialog(this)==DialogResult.OK)
{
changesize_x += (float)Double.Parse(answindow.x_Size.Text);
changesize_y += (float)Double.Parse(answindow.y_Size.Text);
//We would apply
}
answindow.Dispose();
float bmp_x = (float)bmp.Width*changesize_x;
float bmp_y = (float)bmp.Height*changesize_y;
Bitmap final = new Bitmap((int)bmp_x,(int)bmp_y ,pictureBox.CreateGraphics());//扩充图像原来的数组
Graphics g = Graphics.FromImage(final);
Point poi =new Point(0,0);
Size siz = new Size(bmp.Width,bmp.Height);
this.Text=bmp.Width.ToString();
Rectangle r = new Rectangle(poi,siz);
this.Text=siz.Height.ToString(); r = new Rectangle(poi,siz);
g.ScaleTransform(changesize_x,changesize_y);//进行缩放重绘
g.DrawImage(bmp,r);
this.pictureBox.Image = final;
}
/// <summary>
/// 图象旋转处理事件
/// </summary>
float rotatearc = 0;//选择顺时针旋转角度(最好为0-90度,选择其他角度会有图像越界)
private void PicsCircumrotate_Click(object sender, EventArgs e)
{
Circumrotate answindow = new Circumrotate();
if(answindow.ShowDialog(this)==DialogResult.OK)
{
rotatearc += (float)Double.Parse(answindow.arc.Text);
}
answindow.Dispose();
} }
} 我运行了,但总提示Getx_y ,SizeChange ,Circumrotate 出错,找不到。 是怎么回事呢。望高手指点
CSDN小助手是一款脱离浏览器也可以访问Csdn论坛的软件
界面:http://blog.csdn.net/Qqwwee_Com/archive/2005/11/05/523395.aspx
下载:http://szlawbook.com/csdnv2