1

I have some bitmaps in a sub-folder of resource folder (say, Resource/Bitmap) and I want to load them into a bitmap[] at one time, that is,

BitmapSource[] bitmaps=
    TheMethodIWantToImplement(
    new Uri("pack://application:,,,/MyAssembly;component/Resources/Bitmap", 
    UriKind.Absolute));

But I found that Directory.GetFiles does not accept an Uri argument. So...What should I do? Thank you.

Ziyuan
  • 4,215
  • 6
  • 48
  • 77
  • 1
    maybe you can find some help in answers to this question: http://stackoverflow.com/questions/2517407/enumerating-net-assembly-resources-at-runtime – Teudimundo Oct 07 '11 at 06:38

1 Answers1

0

Thank you, @Teudimundo. I modified the snippet of that link as follows:

var asm = Assembly.GetEntryAssembly();
string resName = asm.GetName().Name + ".g.resources";
using (var stream = asm.GetManifestResourceStream(resName))
using (var reader = new System.Resources.ResourceReader(stream))
{
    var paths = from entry in reader.Cast<DictionaryEntry>()
                where ((string)entry.Key).Contains("sub-folder-name")
                select entry.Key;
    if (paths.Any())
    {
        foreach (string path in paths)
        {
            Uri uri = new Uri(String.Format(
                      "pack://application:,,,/{0};component{1}", asm.GetName(), path)
                      , UriKind.Absolute);
            //use the uri for the rest
        }
    }
}

But I still want to use the resource stream directly (can be retrieved via select entry.Value in the LINQ expression above), which is an instance of UnmanagedMemoryStream. I need MemoryStream to construct my object but I found no elegant methods for conversion.

Ziyuan
  • 4,215
  • 6
  • 48
  • 77