Link to home
Start Free TrialLog in
Avatar of visualbasic
visualbasicFlag for Ireland

asked on

How do I load a resource from within my app

I am currently using the folowing syntax to load an Image ,
    upimage.FromFile("C:\Report.bmp")
If a add Report.bmp to my application ,how do I reference or load this Image  from within my app?
Cheers
Avatar of ptakja
ptakja
Flag of United States of America image

Here's what you have to do:

1) Make sure the property "Build Action" is set to "Embedded Resource" for your image file(s). You can see this property by selecting the file in VS and looking at the properties.

2)  To load the file as a resource:

Dim AssyName As String = [Assembly].GetExecutingAssembly.GetName.Name
DIm bmp as New Bitmap = [Assembly].GetExecutingAssembly.GetManifestResourceStream(AssyName & ".Report.bmp")

upimage.Image = bmp

The syntax for the filename in the GetManifestResourceStream method is <assemblyName>.File.extension

Jeff
Avatar of visualbasic

ASKER

this sugestion does not seem to work ,problem is with
DIm bmp as New Bitmap = [Assembly].GetExecutingAssembly.GetManifestResourceStream(AssyName & ".Report.bmp")

do you have any other sugestions

cheers
Do you have the line above it in your code? AND did you follow Step 1 in my original post? I have 2 applications with embedded image resources that work just fine using this exact code (except for the file name) on both the full .NET Framework as well as the Compact Framework.
Whoops...wrong syntax. Try this:

 Comment from ptakja
Date: 11/12/2004 06:36AM EST
 Your Comment  


Here's what you have to do:

1) Make sure the property "Build Action" is set to "Embedded Resource" for your image file(s). You can see this property by selecting the file in VS and looking at the properties.

2)  To load the file as a resource:

Dim AssyName As String = [Assembly].GetExecutingAssembly.GetName.Name
DIm bmp as New Bitmap = [Assembly].GetExecutingAssembly.GetManifestResourceStream(AssyName & ".Report.bmp")

upimage.Image = bmp

The syntax for the filename in the GetManifestResourceStream method is <assemblyName>.File.extension

Jeff
 
Comment from visualbasic
Date: 11/12/2004 12:46PM EST
 Author Comment  


this sugestion does not seem to work ,problem is with
DIm bmp as New Bitmap([Assembly].GetExecutingAssembly.GetManifestResourceStream(AssyName & ".Report.bmp"))
 
 Sorry about that! :-|
ASKER CERTIFIED SOLUTION
Avatar of ptakja
ptakja
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bob Learned
What is the Build Action property set to for the embedded file in the assembly?  Is it Compile, Content, or Embedded Resource?  Are you getting any errors?

Bob
thanks a million ptakja  ,that worked a treat!