"Patrick F" wrote:
Hi, i have a resourcefile with my project that contains a jepg image. Now i
want to retrive that image to a Image m_Image in my program. Whats the best
way to do this?
Assembly a = Assembly.GetExecutingAssembly();
Stream stream = a.GetManifestResourceStream( "MyNamespace.MyImage.jpg" );
if (stream != null)
{
this.m_Image = Bitmap.FromStream( stream ) as Bitmap;
stream.Close();
}
You have to ensure MyImage.jpg is included in your project and marked as an
"Embedded Resource" in its properties. In the example above, MyImage.jpg
must be located in the root project folder. If it's located in a subfolder,
such as "Art", you would need to add that to the path, using a period instead
of backslash, such as:
"MyNamespace.Art.MyImage.jpg"
If the image is not loading, you can confirm its existence and path in your
resource file by adding the following line to the code above:
// use this to get the names of all resources in your assembly
string [] resNames = a.GetManifestResourceNames();
--
Timm Martin
Mini-Tools
..NET Components and Windows Software
http://www.mini-tools.com