Use image in project as a resource

  • Thread starter Thread starter sklett
  • Start date Start date
S

sklett

I've got a couple images in my project that I need to pass to some other
assemblies. I waned to pass them as an Image object. I was hoping there
was some way that I could load the images files without needing to use the
full path and Image.FromFile() - it seems that there should be some way to
reference assets in the project without giving their full path. Anyone know
how?

For example, I would like to do something like this:
Image myIMage = (Image)MyNamespace.MyImageFileInMyProject.png;

Something *close* to that would be great.

Thanks for any suggestions!
Steve
 
Steve,
if the image is included in the project and has been marked as "Embedded
Resource" then you can gain access to it with the GetManifestResourceStream
method of the Assembly class.
You can use GetManifestResourceNames, which returns a string array, to see
exactly how each resource can be referred to.
Peter
 
Perfect, thanks Peter!
I'm actually using a class library, so I had a little more research to get a
reference to my Assembly, but it works great now. Appreciate your help.

-Steve
 
Back
Top