使用wpf图像控件显示文件系统中的图像

时间:2021-09-13 00:22:28

I want to show an image from a file using an wpf image control. The image file resides in the application directory.

我想使用wpf图像控件显示文件中的图像。映像文件位于应用程序目录中。

<Image Stretch="Fill" Source="dashboard.jpg" />

The file dashboard.jpg should be replaceable during or after deployment. How do I have to add the image to the project and what BuildAction do I have to use to have the image read from the file system rather than any source I cannot change after deployment. What source uri do I have to use?

文档dashboard.jpg在部署期间或之后应该可以替换。我如何将图像添加到项目中以及必须使用哪些BuildAction来从文件系统读取图像,而不是在部署后无法更改的任何源。我必须使用什么来源uri?

3 个解决方案

#1


12  

just have a look at this link

只是看看这个链接

Setting WPF image source in code or

在代码或中设置WPF图像源

Dynamic loading of images in WPF

在WPF中动态加载图像

#2


21  

ImageSource imageSource = new BitmapImage(new Uri("C:\\FileName.gif"));    
image1.Source = imageSource;

#3


17  

In markup:

在标记中:

<Image Stretch="Fill">
    <Image.Source>
        <BitmapImage UriSource="dashboard.jpg"/>
    </Image.Source>
</Image>

#1


12  

just have a look at this link

只是看看这个链接

Setting WPF image source in code or

在代码或中设置WPF图像源

Dynamic loading of images in WPF

在WPF中动态加载图像

#2


21  

ImageSource imageSource = new BitmapImage(new Uri("C:\\FileName.gif"));    
image1.Source = imageSource;

#3


17  

In markup:

在标记中:

<Image Stretch="Fill">
    <Image.Source>
        <BitmapImage UriSource="dashboard.jpg"/>
    </Image.Source>
</Image>