471,605 Members | 1,466 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,605 software developers and data experts.

Use image in project as a resource

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
Feb 12 '06 #1
2 2005
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

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"sklett" wrote:
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

Feb 13 '06 #2
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

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:06**********************************@microsof t.com...
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

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"sklett" wrote:
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

Feb 13 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Saya | last post: by
2 posts views Thread by Don Tucker | last post: by
5 posts views Thread by aiki727 via DotNetMonster.com | last post: by
3 posts views Thread by UJ | last post: by
2 posts views Thread by Patrick F | last post: by
3 posts views Thread by bbrewder | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by CCCYYYY | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.