1

I'm having problems getting images from my Properties.Resources into an array. Each image has its own name, but I can't find a way to easily put them into an array without manually typing them all out like so.

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

etc.

Is there an easy way to make an array from my Resources.resx file, without changing the names of the files?

Fuzzyketchup
  • 153
  • 1
  • 2
  • 17

1 Answers1

0

You can use the ResourceSet to generate the array:

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();
Jason W
  • 12,771
  • 3
  • 26
  • 58