Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Help loading an Embedded Bitmap Object.

Status
Not open for further replies.

NipsMG

Programmer
Dec 27, 2000
215
US
The name of my project is DXTest (DXTest is the root namespace).

I have a folder under my project called Bitmaps, with a subfolder called Title, containing a title.jpg.

Title.jpg is an embedded resource.

I am converting a project that is in C# code to try to load this embedded file into a bitmap object.

The code is as follows:

Code:
'NOTE: Resource is a string containing "DXTest.Bitmaps.Title.title.jpg"

sourceBitmap = New Bitmap(GetType().Module.Assembly.GetManifestResourceStream(Resource))

The problem is, gettype().xxxxx is not allowed. I have tried me.GetType.Module.etc etc etc, but I always come back with a "null stream" error.

I *may* be approaching this totally wrong, as I have no C# experience, but I've had good luck converting the other 99.99999% of the project thus far.

Any help would be greatly appreciated.

Thanks!

--NipsMG s-)
 
OK, I've gotten so far as loading a bitmap stored directly under the project.

My problem is now, trying to load a bitmap stored in a folder under my project.

Code:
sourceBitmap = new Bitmap(me.GetType().Module.Assembly.GetManifestResourceStream(Me.GetType().Assembly.Namespace & ".title.jpg"))

is sufficient to load title.jpg residing directly under my project.

Now, from what I've read, I should be able to access a file in a folder called Bitmaps\Title under my project by extemding ".title.jpg" to ".Bitmaps.Title.title.jpg"

However, I have not gotten this to work.

Anyone know what I'm doing wrong? :(

--NipsMG
 
If your .jpg is an embedded resource then you should just be able to do ( should work for icons too)

sourceBitmap = new Bitmap(me.getType(), "title.jpg")

you need to make sure that the title.jpg is spelled exactly correct or else it won't find it.

if it isn't an embedded resourc then you should be able to do

source bitmap = new bitmap(filename)
(where filename look something like "c:\ myproject\bitmaps\title.jpg")

Hope that this helps.
 
I had read some previous articles on loading embedded bitmaps, and if the bitmap was in a folder under the project, you had to specify the folder name. Now, it seems you no longer need to do that in vs2k3.

Thanks for your help.

--NipsMG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top