Home » SharepointRSS

How to extract image from a dll?

This is not exactly a WPF question, but rather a generic C# question.

 

I have a DLL with multiple png images added as resources. I can easily access those images in wpf when I know the full path, but I would like to add a browsing

functionality which will let me browse through all the images.

I know how to extrac class information from an assembly through reflection, but how can I obtain the embedded resources?, is this at all possible through .NET or do I have to look into using some Win32 APIs for this ?

 

Thanks

 

 

3 Answers Found

 

Answer 1

1) Getting image  names from dll  as a list

http://stackoverflow.com/questions/1044057/getting-image-names-from-dll-as-a-list

2) Retrieving an embedded  image from a DLL

http://bytes.com/topic/c-sharp/answers/277865-retrieving-embedded-image-dll

3) Embedded Image Resources

http://www.csharp411.com/embedded-image-resources/

Show all embedded resources:

Assembly myAssembly = Assembly.GetExecutingAssembly();
string[] names = myAssembly.GetManifestResourceNames();
foreach (string name in names)
{
    Console.WriteLine( name );
}

These links might help you.

 

 

Answer 2

I had already tried the GetManifestResrouceNames and it does not return the names of the images.

I will take a look at the other links

thanks

 

Answer 3

ahh - this from your first link was exactly what I was looking for

  public static List<string> GetImageList(Assembly assembly)
  {
   System.Globalization.CultureInfo culture = System.Threading.Thread.CurrentThread.CurrentCulture;
   string resourceName = assembly.GetName().Name + ".g";
   System.Resources.ResourceManager rm = new System.Resources.ResourceManager(resourceName, assembly);
   System.Resources.ResourceSet resourceSet = rm.GetResourceSet(culture, true, true);
   List<string> resources  = new List<string>();
   foreach (DictionaryEntry resource in resourceSet)
   {
    resources.Add((string)resource.Key);
   }
   rm.ReleaseAllResources();
   return resources;
  }

 

 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter