打开文件对话框选择图片
//浏览图片方法
private void Browse(Image img)
{
try
{
string strImage = "";
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "所有文本文件(*.jpg;*.gif;*.png)|*.jpg;*.gif;*.png";
if (dlg.ShowDialog() == true)
{
strImage = dlg.FileName;
}
if (strImage != "")
{
BitmapImage image = new BitmapImage(new Uri(strImage, UriKind.Absolute));
img.Source = image;
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
红色代码说明:直接付给Image的Source 的路径不好用,必须先转换一下
本文来自忘了忘不了的博客,原文地址:http://blog.sina.com.cn/s/blog_6f99d8ea0100v0b7.html