【问题标题】:Use wpf image control to show an image from filesystem使用 wpf 图像控件显示来自文件系统的图像
【发布时间】:2011-05-18 23:22:13
【问题描述】:
我想使用 wpf 图像控件显示来自文件的图像。图像文件位于应用程序目录中。
<Image Stretch="Fill" Source="dashboard.jpg" />
文件dashboard.jpg 在部署期间或部署后应该是可替换的。如何将图像添加到项目中,以及我必须使用什么 BuildAction 来从文件系统读取图像,而不是在部署后无法更改的任何源。我必须使用什么源 uri?
【问题讨论】:
标签:
wpf
image
wpf-controls
【解决方案1】:
ImageSource imageSource = new BitmapImage(new Uri("C:\\FileName.gif"));
image1.Source = imageSource;
【解决方案2】:
在标记中:
<Image Stretch="Fill">
<Image.Source>
<BitmapImage UriSource="dashboard.jpg"/>
</Image.Source>
</Image>