嵌入式二进制资源 - 如何枚举嵌入的图像文件?

Pet*_*háč 4 .net c# resources visual-studio-2010 embedded-resource

我按照本书中的说明,有关资源等的章节,以及我无法弄清楚的是,如何替换它:

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)));
Run Code Online (Sandbox Code Playgroud)

通过一个循环,它将简单地遍历所有嵌入的图像资源,以避免硬编码图像名称和路径.我将如何发现嵌入文件的名称?

我确实选择了我想要嵌入和指定的图像:

构建操作=资源并复制到输出目录=不要复制

在"属性"窗口中.组件的尺寸已经大大增加,我相信图像确实已经嵌入.

Ore*_*zor 5

尝试使用GetManifestResourceNames,或查看ResourceManager对象.

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