设置wpf图像的imagesource [英] Set imagesource of wpf image

查看:1787
本文介绍了设置wpf图像的imagesource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有一些类似的问题,但他们没有帮助我:

I know that there are a few similiar questions but they don´t help me:

有以下代码在后面的代码中显示图像:

Have got the following code to show a Image in code behind:

BitmapImage logo = new BitmapImage();
logo.BeginInit();
logo.UriSource = new `Uri("pack://application:,,,/ApplicationName;component/Images/Klar.JPG");`
logo.EndInit();

图像位于Images文件夹中,与 bin <相同/ code>文件夹。

The image is in the Images folder at the same level as the bin folder.

我的错误是什么?

推荐答案

有关包URI的信息请参阅此处。我相信你的应该是:

For information about Pack URIs see here. I believe yours should be:

logo.BeginInit();
logo.UriSource = new Uri("pack://application:,,,/Images/Klar.JPG");
logo.EndInit();

假设您在项目级别有一个名为Images的文件夹,其中包含一个名为Klar.JPG的jpg 。

which assumes that at the project level you have a folder called Images which contains a jpg called Klar.JPG.

这篇关于设置wpf图像的imagesource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆