如果想要点击一个按钮来选择图片,则可在Windows窗体应用程序中在Button控件中输入以下代码:
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog Openfile = new OpenFileDialog();//创建打开文件对话框
if (Openfile.ShowDialog() == DialogResult.OK)//打开的文件对话框如果选择了OK按钮,则为真,执行大括号中的内容
{
Image<Bgr, Byte> My_Image = new Image<Bgr, byte>(Openfile.FileName);//以打开的图片文件创建My_Image
pictureBox1.Image = My_Image.ToBitmap();//在以创建的pictureBox1控件中显示位图
}
}
如果想要以灰阶图显示出来而不是原图,则可以把
Image<Bgr, Byte> My_Image = new Image<Bgr, byte>(Openfile.FileName);改成Image<Gray, byte> My_Image = new Image<Gray, byte>(Openfile.FileName);
如果想把Byte图转换成double图,需要强制转换,加上这句 Image<Gray,double> gray_image = My_Image.Convert<Gray,double>();后面显示时把My_Image换成gray_image