2014-11-04 69 views
1

我在從Properties.Resources獲取圖像到數組中時出現問題。每張圖片都有自己的名字,但是我找不到一種方法可以輕鬆地將它們放入數組中,而無需像這樣手動輸入。從resx文件中獲取圖像數組C#

System.Drawing.Bitmap[] imageArray = new System.Drawing.Bitmap[29]; 
imageArray[0] = Properties.Resources.acorno; 
imageArray[1] = Properties.Resources.batterymanD; 
imageArray[2] = Properties.Resources.batterymanMicroCell; 

有一個簡單的方法,使從我Resources.resx文件中的數組,在不改變文件的名稱?

+0

是你熟悉的foreach'()'方法..?你可以實現基於集合的東西,例如 – MethodMan 2014-11-04 17:53:26

+0

我不熟悉foreach()方法,有沒有一個鏈接可以指導我理解它? – Fuzzyketchup 2014-11-04 17:54:24

+0

做一個谷歌搜索,以及循環通過資源文件C#這裏是另一個鏈接是在StackOverflow,可以幫助你http://stackoverflow.com/questions/2041000/loop-through-all-the-resources-in-a -resx-file – MethodMan 2014-11-04 17:56:54

回答

0

可以使用的ResourceSet生成數組:

var resourceSet = Properties.Resources.ResourceManager.GetResourceSet(System.Globalization.CultureInfo.CurrentUICulture, true, true); 
System.Drawing.Bitmap[] imageArray = resourceSet.OfType<System.Collections.DictionaryEntry>() 
    .Select(i => (System.Drawing.Bitmap)i.Value) 
    .ToArray();