1using System.Reflection;
2using System.IO;
3
4/// <summary>
5/// Gets an embedded image from the current assembly.
6/// </summary>
7/// <param name="imagePath">Full namespace path of the image.</param>
8/// <returns>The image found at <paramref name="imagePath"/>.</returns>
9/// <example>
10/// The root namespace of your project is MyCompany.MyApp and you have
11/// an image named foo.png in a folder named Images. The imagePath would
12/// be MyCompany.MyApp.Images.foo.png.
13/// </example>
14public Image GetEmbeddedImage(string imagePath)
15{
16 // Embedded items are found in the assembly manifest
17 Assembly thisAssembly = Assembly.GetAssembly(this.GetType());
18 Stream resourceStream = thisAssembly.GetManifestResourceStream(imagePath);
19 return Image.FromStream(resourceStream);
20}
21