Use an image that I have "attached" to the project

  • Thread starter Thread starter Ulf Christenson
  • Start date Start date
U

Ulf Christenson

Hello!
I have added a .png image so that it is shown in the Solution Explorer
beside the .vb files.
Now I am trying to use this image, but it doesn't want.
I simply don't get the "path" to it.
Can somebody help me?
Ulf
 
Ulf Christenson said:
I have added a .png image so that it is shown in the Solution Explorer
beside the .vb files.
Now I am trying to use this image, but it doesn't want.
I simply don't get the "path" to it.
Can somebody help me?

You may want to embed the image as a resource. This can be done in "My
Project" -> "Resources". Afterwards the image can be accessed using
'My.Resources.*'.

If you want to keep the image a separate file, make sure you set its build
action appropriately, in order to get the image copied to the destination
folder.
 
No, I mean it differently...

This line fails:
-------------Private imgSplash As System.Drawing.Image =
System.Drawing.Image.FromStream(GetResource("Splash Screen.png"))

(It says "Null is invalid for stream")

in this code:

Private imgSplash As System.Drawing.Image =
System.Drawing.Image.FromStream(GetResource("Splash Screen.png"))
Private Shared m_Assembly As System.Reflection.Assembly =
System.Reflection.Assembly.GetExecutingAssembly()
Private Shared m_AssemblyPath As String =
m_Assembly.GetName().Name().Replace(" ", "_")

Public Shared Function GetResource(ByVal FileName As String) As
System.IO.Stream
Return m_Assembly.GetManifestResourceStream(m_AssemblyPath &
"." & FileName)
End Function

Ulf
 
Ulf said:
Pardon me?


The ressource name must contain the root namespace name:


Private imgSplash As System.Drawing.Image =
System.Drawing.Image.FromStream(GetResource("<root namespace>.Splash
Screen.png"))


Armin
 
You mean that when my solution is named "WindowsApplication11", then it
has to be

"WindowsApplication11.Splash Screen.png"?

This doesn't work for me.
Do you have any other hint for me?

Thank you!!
Ulf
 
Perhaps what he did was "drag and drop" the item into the solution explorer,
but did not add it into the referece portion?
 
Ulf Christenson said:
You mean that when my solution is named "WindowsApplication11", then it
has to be

"WindowsApplication11.Splash Screen.png"?

This doesn't work for me.
Do you have any other hint for me?

Thank you!!
Ulf

Yes, that is what he is saying to do. In solution explorer, select the
file, and make sure the property "Build Action" says "Embedded Resource".

Mike
 
Ulf,

Try this for a sec,

In the solutions explorer, double click on "My Project"

Then click on the Resources tab.
Then in the top, click on the dropdown ( most likely it says strings ) and
select images.

Is your image in this file here?
If No, what happens if you drag your file into this window?

Miro
 
Ulf said:
I have changed the .png's propery to EmbeddedRessource now, but still
the same error.
Is anybody willing to take a look at the project? I don't know what
else to do.

I have uploaded it here:
http://rapidshare.com/files/205734802/WindowsApplication11.zip.html

Well, you already did use the root namespace before. Sorry, I misread the
code (just read GetResource("Splash Screen.png")). So, what was missing was
just build action=embedded ressource. If you remove the additional
"windowsapplication11.", it should work now.


Armin
 
Ulf Christenson said:
No, I mean it differently...

This line fails:
-------------Private imgSplash As System.Drawing.Image =
System.Drawing.Image.FromStream(GetResource("Splash Screen.png"))

(It says "Null is invalid for stream")

Which version of .NET are you using? As you are using an embedded resource,
I wonder why you are not making use of "My Project" -> "Resources" +
'My.Resources.*'.
 
Back
Top