Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

HowTo: Reference Bitmap in project (EASY 500 pts)

Posted on 2004-08-20
5
Medium Priority
?
225 Views
Last Modified: 2010-04-23
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...
0
Comment
Question by:ptakja
  • 2
  • 2
5 Comments
 
LVL 10

Expert Comment

by:eternal_21
ID: 11852650
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
 
LVL 7

Expert Comment

by:ramesh12
ID: 11852699
Dim bmp As New Bitmap( server.mappath("./Mybitmap.bmp"))
0
 
LVL 14

Author Comment

by:ptakja
ID: 11853793
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
 
LVL 7

Accepted Solution

by:
ramesh12 earned 2000 total points
ID: 11853920
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
 
LVL 14

Author Comment

by:ptakja
ID: 11854156
ramesh12...that worked great.  Learned something new today!  WOOHOO!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Integration Management Part 2
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question