动态添加和C#从资源加载图像

问题描述:

我已经添加到我的解决方案的一些图像,现在它是解决方案资源管理器内的文件夹下images\flowers\rose.png。我想办法这个图像动态加载到我的图像控制。

I have some images added to my solution, right now it is under the folder images\flowers\rose.png inside the solution explorer. I want a way to dynamically load this image to my image control.

我目前的做法是使该类型'内容',用'复制总是属性。然后我会给相对路径的形象像下面。

My current approach is making the type 'content' and use 'copy always' properties. Then i would give relative path to the image like below.

Image2.Source = new BitmapImage(new Uri("/images/flowers/Customswipe_b.png", UriKind.Relative));



有没有什么办法让它从资源加载,而不将其复制到目标系统。

Is there any way to make it load from the resource without copying it to the target system.

下面的工作就好了我:

image.Source = new BitmapImage(new Uri("pack://application:,,,/YourAssemblyName;component/Resources/someimage.png", UriKind.Absolute));



另外,应修改生成操作的从资源