HowTo: Reference Bitmap in project (EASY 500 pts)

Ok.. I am stumped by this one.

I have a project that has 2 bitmap file as part of the project.  In code I need to load these bitmaps into memory so I can display them.   So how can I reference these files without an explicit file path in the bitmap's constructor?

Dim bmp As New Bitmap("Mybitmap.bmp")   <<< this fails at runtime.  Says it can't find the file...
LVL 14
ptakjaAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ramesh12Connect With a Mentor Commented:
i think we can embed in the following way

if you see image properties :

buildaction : chnage this to embedded resource


and you can reference it in your app something like this

Dim bmp As New Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("<namespace>.<imagename>"));
0
 
eternal_21Commented:
Make sure that the bitmap file is actually in the output folder (i.e. bin\Debug, or bin\Release), if so, your code should run fine.
0
 
ramesh12Commented:
Dim bmp As New Bitmap( server.mappath("./Mybitmap.bmp"))
0
 
ptakjaAuthor Commented:
This is for a WinForms app.

eternal_21, what if all I want to deploy is a dll.  In other words, I don't want to deply the bmp as a separate file.  I want it all rolled into the dll.

Do you know how to embed an image as a resource?
0
 
ptakjaAuthor Commented:
ramesh12...that worked great.  Learned something new today!  WOOHOO!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.