动态添加和C#从资源加载图像 [英] Dynamically adding and loading image from Resources in C#

查看:1070
本文介绍了动态添加和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));



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

这篇关于动态添加和C#从资源加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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