0

I want to find an easier way of accessing images in a satellite DLL, so I was trying to put them into a List, like this:

{
images = new List<Bitmap>();
// 1. The Fool
using (var ms = new MemoryStream(Properties.Resources.tarot_1_TheFool))
{ 
   Bitmap bmp = new Bitmap(ms);
   images.Add(bmp);
}

}

Is there a way to enumerate through Settings images, or do I have to load each image via a MemoryStream object as shown in above code?

Su Llewellyn
  • 2,660
  • 2
  • 19
  • 33
  • 1
    The code is wrong here: `using (var ms = new MemoryStream(Properties.Resources.tarot_1_TheFool))`. I assume `tarot_1_TheFool` is a Bitmap, you don't usually store byte arrays in Resources. So you cannot pass a Bitmap to a MemoryStream. Then, to use a MemoryStream as the source Stream of a Bitmap, the Stream must be *alive*, so don't declare it with a `using` statement. Also, you really need to use this constructor: `Bitmap bmp = new Bitmap(ms, true);` or the similar `Image.FromStream()`. – Jimi Mar 08 '20 at 23:00
  • In my source code, here is what it looks like when I try to access the Properties Settings: {Bitmap tarotCard = TarotResources.Properties.Resources.tarot_10_TheHermit;} yields the error "Cannot implicitly convert type 'byte[]' to 'System.Drawing.Bitmap' – Su Llewellyn Mar 08 '20 at 23:27
  • You are right - it's a Bitmap. I hadn't understood the MemoryStream must be 'alive' - I don't understand what you mean. I like your idea Image.FromStream. I'll try that! – Su Llewellyn Mar 08 '20 at 23:34
  • That worked great! Thanks! If you could add your comment as an "answer" I will accept it. and Thanks – Su Llewellyn Mar 08 '20 at 23:39
  • @Zer0 - Yes that does answer my question! I didn't know the ResourceSet would do it. That'll shorten my code. Thanks! – Su Llewellyn Mar 09 '20 at 00:41

0 Answers0