Embedded Resource (PNG) in DLL

  • Thread starter Chris Murphy via DotNetMonster.com
  • Start date
C

Chris Murphy via DotNetMonster.com

Hi all, I've been strugling with this for the last few days and I'm wonding
if any of you have had the same problem or a solution I could consider: I'm
embedding a bitmap resource (PNG format) as part of an extended panel control
that I'm creating. I'm trying read the embedded resource and draw it out on
the panel. The drawing part I know how to do well enough, but for some reason
when I try to access the embedded resource (PNG = "header_image.png") it
always returns an empty stream (using helper methods wrapping
GetManifestResource...). I'm stumped. Please help!
 
B

Brian Henry

do you have the root namespace before the resource name? example
MyRootNamespace.picture.png
 
C

Chris Murphy via DotNetMonster.com

I have some methods that take care of that

Private AppAssembly As Reflection.Assembly = Reflection.Assembly.
GetExecutingAssembly()
Private AppAssemblyPath As String = Me.AppAssembly.GetName().Name().
Replace(" ", "_")

Private Function GetResource(ByVal FileName As String) As System.IO.
Stream
Try
Return Me.AppAssembly.GetManifestResourceStream(Me.
AppAssemblyPath & "." & FileName)
Catch ex As Exception
MessageBox.Show("Error returning resource: " & ex.ToString(),
"XiNK!", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return Nothing
End Try
End Function

Brian said:
do you have the root namespace before the resource name? example
MyRootNamespace.picture.png
Hi all, I've been strugling with this for the last few days and I'm
wonding
[quoted text clipped - 9 lines]
always returns an empty stream (using helper methods wrapping
GetManifestResource...). I'm stumped. Please help!
 
B

Bob Powell [MVP]

Your app assembly path idea is flawed. Do as Brian suggested and use the
root namespace as declared in your project. See Windows Forms Tips and
Tricks for an article on how to find resources.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





Chris Murphy via DotNetMonster.com said:
I have some methods that take care of that

Private AppAssembly As Reflection.Assembly = Reflection.Assembly.
GetExecutingAssembly()
Private AppAssemblyPath As String = Me.AppAssembly.GetName().Name().
Replace(" ", "_")

Private Function GetResource(ByVal FileName As String) As System.IO.
Stream
Try
Return Me.AppAssembly.GetManifestResourceStream(Me.
AppAssemblyPath & "." & FileName)
Catch ex As Exception
MessageBox.Show("Error returning resource: " & ex.ToString(),
"XiNK!", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return Nothing
End Try
End Function

Brian said:
do you have the root namespace before the resource name? example
MyRootNamespace.picture.png
Hi all, I've been strugling with this for the last few days and I'm
wonding
[quoted text clipped - 9 lines]
always returns an empty stream (using helper methods wrapping
GetManifestResource...). I'm stumped. Please help!
 
C

Chris Murphy via DotNetMonster.com

I id just that, thank you!
Your app assembly path idea is flawed. Do as Brian suggested and use the
root namespace as declared in your project. See Windows Forms Tips and
Tricks for an article on how to find resources.
I have some methods that take care of that
[quoted text clipped - 23 lines]
 

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