从Resources.resx分配的BitmapImage到Image.Source? [英] Assign BitmapImage from Resources.resx to Image.Source?

查看:203
本文介绍了从Resources.resx分配的BitmapImage到Image.Source?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的Resources.resx分配的BitmapImage 图片
在此之前我保存为.png图像Resources.resx。现在该映像位于/Resources/logo.png。

I would like to assign a BitmapImage from my Resources.resx to an Image. Beforehand I saved a .png image to Resources.resx. This image is now located in "/Resources/logo.png".

读取多个职位SO等文章后,我有现在这样:

After reading several SO posts and other articles I have this now:

logoImage.Source = new BitmapImage(new Uri(@"pack://application:,,,/Resources/logo.png"));

不幸的是它不工作。
我不知道如何解决这个问题。

Unfortunately it doesn't work. I don't know how to solve this.

我试图替换包-URI 的完整路径和它的工作,但我想为了使用不同的机器上相同的源使用相对路径上绝对路径是不正确的。

I tried to replace the Pack-URI with the fullpath and it worked but I would like to use relative paths in order to use the same source on different machines on which the absolute path would be incorrect.

谁能帮我这个?
在此先感谢!

Can anyone help me out with this? Thanks in advance!

推荐答案

为了使该乌里工作,文件logo.png必须包含在你的VS项目命名为资源文件夹中(见第一幅图像)其生成操作必须设置为资源(见第二个图)。

In order to make that Uri work, the file logo.png must be contained in a folder named "Resources" in your VS project (see first image), and its build action must be set to Resource (see second image).

这资源文件夹是完全无关的Resources.resx。你可以把它重命名为任何你喜欢的。

This Resources folder is completely unrelated to Resources.resx. You may rename it to whatever you like.

这篇关于从Resources.resx分配的BitmapImage到Image.Source?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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