Use image in project as a resource

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
 
G

Guest

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
 
S

Steve

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top