Embedded images?

E

elziko

I'm trying to use an embedded image(bitmap) using the following code:

imgDrag = New
System.Drawing.Bitmap(GetType(QueryResultGrid).Assembly.GetManifestResourceS
tream("Comp.Tech.QueryResultGrid.ResultsGridDrag.bmp"))

Where QueryResultGrid is the class thats going to use the image,
Comp.Tech.QueryResultGrid is the assembly name and ResultsGridDrag.bmp is
the file name of the embedded resource. However, on runing this line I get:

An unhandled exception of type 'System.ArgumentException' occurred in
system.drawing.dll
Additional information: 'null' is not a valid value for 'stream'.

Any ideas why? I think that maybe I should be using something other than
"Comp.Tech.QueryResultGrid.ResultsGridDrag.bmp"?
 
K

Ken Tucker [MVP]

Hi,

Here is an example. I added the water lilies.jpg to my app get its
build action to embedded resource.
Dim bm As Bitmap

Dim myAsm As System.Reflection.Assembly =
System.Reflection.Assembly.GetExecutingAssembly()

bm = New Bitmap(myAsm.GetManifestResourceStream(Me.GetType, "Water
lilies.jpg"))



Ken
 
H

Herfried K. Wagner [MVP]

* "elziko said:
I'm trying to use an embedded image(bitmap) using the following code:

imgDrag = New
System.Drawing.Bitmap(GetType(QueryResultGrid).Assembly.GetManifestResourceS
tream("Comp.Tech.QueryResultGrid.ResultsGridDrag.bmp"))

Where QueryResultGrid is the class thats going to use the image,
Comp.Tech.QueryResultGrid is the assembly name and ResultsGridDrag.bmp is
the file name of the embedded resource. However, on runing this line I get:

An unhandled exception of type 'System.ArgumentException' occurred in
system.drawing.dll
Additional information: 'null' is not a valid value for 'stream'.

Any ideas why? I think that maybe I should be using something other than
"Comp.Tech.QueryResultGrid.ResultsGridDrag.bmp"?

Does it work it you use something like that?

Add the image, set its 'Build Action' to 'Embedded Resource', then you
can use this code to load the bitmap:

\\\
Me.picMyPicture.Image = _
New Bitmap( _
System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream( _
"<Root namespace>.<File name>" _
) _
)
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top