views:

174

answers:

2

I am adding a splash screen to a .NET compact application and am wondering if there's an elegant way to access the correct bitmap (based on screen resolution) for the splash screen.

e.g. My resource bitmap properties are named like this...

Splash640480

Splash480640

Splash480480

Splash320240

Splash240320

Splash240240

... etc

I tried making a generic dictionary but loading the generics library on a Pocket PC is quite slow - it took 6 seconds before the splash screen displayed vs 2 seconds when simply assigning a bitmap.

Would reflection be a fast option and if so, what's the best way to go about it?

+5  A: 

You can use the ResourceManager to get an object by it's name:
http://msdn.microsoft.com/en-us/library/system.resources.resourcemanager.getobject.aspx

After that cast it to a bitmap.

Zyphrax
+2  A: 
System.Resources.ResourceManager resources = 
    new System.Resources.ResourceManager(typeof(YourObject));
Bitmap bmp = (System.Drawing.Bitmap)resources.GetObject("Splash640480");

Edit:

Removing the suggestion to downsize the image.

Francis B.
Not a good idea in Windows Mobile - Bitmap memory is allocated in dedicated video RAM, which is usually 4MB or even 1MB (instead of the 32MB theoretically available to each process). You generally don't want to create Bitmaps any larger than what you actually need.
MusiGenesis
Ha! good to know
Francis B.