本文介绍了WPF图像控制源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试重新建立一个C#项目,我WPF中,它的一个简单的图像浏览器..一个非常简单的例子,从山姆教你C#,香港专业教育学院设法打开文件对话框打开,但我怎么设置图像路径在WPF中image.source控制?
私人无效SearchBtn_Click(对象发件人,RoutedEventArgs E)
$ { b $ b Microsoft.Win32.OpenFileDialog打开文件=新Microsoft.Win32.OpenFileDialog();
openfile.DefaultExt =* .JPG;
openfile.Filter =图像文件| * .JPG;
可空<布尔>结果= openfile.ShowDialog();
如果(结果==真)
{
//imagebox.Source = openfile.FileName;
}
}
解决方案
imagebox.Source =新的BitmapImage(新的URI(openfile.FileName));
im trying to recreate a very simple example of a C# project i WPF, its a simple image viewer.. from the sam's teach yourself C#, ive managed to get the open file dialog to open, but how do i set the image path to the image.source control in WPF?
private void SearchBtn_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog openfile = new Microsoft.Win32.OpenFileDialog();
openfile.DefaultExt = "*.jpg";
openfile.Filter = "Image Files|*.jpg";
Nullable<bool> result = openfile.ShowDialog();
if (result == true)
{
//imagebox.Source = openfile.FileName;
}
}
解决方案
imagebox.Source = new BitmapImage(new Uri(openfile.FileName));
这篇关于WPF图像控制源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!