图像处理-01-加载图像文件
加载图像文件
public Form1() { InitializeComponent(); this.pbImage.SizeMode = PictureBoxSizeMode.Zoom;//图像大小按原有比例增大或缩小以适应PictureBox的长宽 } private void btnOpen_Click( object sender, EventArgs e ) { OpenFileDialog openImage = new OpenFileDialog(); openImage.Title = "请打开图像文件";//弹出对话框的标题 openImage.Filter = "(图像文件)*.bmp;jpg;jpeg;gif;png|*.bmp;*.jpg;*.jpeg;*.gif;*.png";//打开文件对应的格式 openImage.InitialDirectory = @"D:/";//设置对话框显示的初始目录为C盘 openImage.FilterIndex = 1; openImage.RestoreDirectory = true;//在关闭对话框前还原当前目录 if (openImage.ShowDialog() == DialogResult.OK) { txtImageFilePath.Text = openImage.FileName;//打开图像的完整路劲 this.pbImage.Image = System.Drawing.Bitmap.FromFile( txtImageFilePath.Text );//加载图像 } } }