嵌入式二进制资源 - 我怎么能列举出的图像文件中嵌入的? [英] Embedded Binary Resources - how can I enumerate the image files embedded?

查看:109
本文介绍了嵌入式二进制资源 - 我怎么能列举出的图像文件中嵌入的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面就资源这本书,章等什么我不能完全弄清楚的是,我怎么替换这样的:

I was following the instructions in this book, chapter on Resources etc. and what I can't quite figure out is, how do I replace this:

images.Add(new BitmapImage(new Uri(@"/Images/Deer.jpg", UriKind.Relative)));
images.Add(new BitmapImage(new Uri(@"/Images/Dogs.jpg", UriKind.Relative)));
images.Add(new BitmapImage(new Uri(@"/Images/Welcome.jpg", UriKind.Relative)));

由只会通过所有嵌入的图像资源运行,以避免硬编码的图像名称和路径循环。我怎么会去发现嵌入的文件的名字?

by a loop that would simply run through all embedded image resources to avoid hard-coding the image names and paths. How would I go about discovering the names of the embedded files?

我没有选择,我想嵌入图像的规定:

I did select the images I wanted to embed and specified:

生成操作=资源,并复制到输出目录=不要复制

Build Action=Resource and Copy to Output Directory=Do not copy

在属性窗口。装配有了很大的发展规模,我很确信图片确实被嵌入。

in the Properties window. The assembly has grown considerably in size and I am quite convinced the images have indeed been embedded.

推荐答案

试一下用GetManifestResourceNames,或可考虑的ResourceManager对象。

try something using GetManifestResourceNames, or look into the ResourceManager object.

Assembly assembly = Assembly.GetExecutingAssembly();
foreach (string s in assembly.GetManifestResourceNames())
{
    //match on filenames here. you can also extention matching to find images.
}

这篇关于嵌入式二进制资源 - 我怎么能列举出的图像文件中嵌入的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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