Solved

HowTo: Reference Bitmap in project (EASY 500 pts)

Posted on 2004-08-20
5
214 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 500 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now