2010-09-24 43 views
4

我按照this book,資源等章節中的說明進行操作,而我無法弄清楚的是,我如何用一個循環來替換它:嵌入式二進制資源 - 如何枚舉嵌入的圖像文件?

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))); 

資源,以避免硬編碼圖像名稱和路徑。我將如何發現嵌入文件的名稱?

我選擇了我想要嵌入和指定的圖像:

構建操作=資源並複製到輸出目錄=不要在屬性窗口中複製

。組件的尺寸已經大大增加,我相信這些圖像確實已經嵌入。

回答

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. 
}