• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1255
  • Last Modified:

C# GetManifestResourceStream - how to reference an embedded resource

Hi..
I have an image file in a project under an images folder.  
...images/myImage.png

How do I reference it in GetManifestResource stream?
It's an embedded resource.

GetManifestResourceStream('MyAssembly.resources.myImage.png') does not work... what should it be..

0
JElster
Asked:
JElster
  • 3
  • 2
1 Solution
 
Carlos VillegasFull Stack .NET DeveloperCommented:
You can do this:
System.Drawing.Image myImage = System.Drawing.Image.FromStream(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("MyAssembly.resources.myImage.png"))

Open in new window


Use:
System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames()

Open in new window

To read yours resources names.
0
 
JElsterAuthor Commented:
None of the resource names have the image file in it.
When I  'add the name'  I get invalid parameter
0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Check the file properties in your project, "Build Action" must be set to "Embedded Resource"
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Just FYI, for WinForms you can also do something like:

        private void button1_Click(object sender, EventArgs e)
        {
            Bitmap bmp = new Bitmap(this.GetType(), "myImage.png");
            pictureBox1.Image = bmp;
        }
0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Hello Idle_Mind, mmm I see, I tested it, just I have to remove the root namespace from the resource name to make it work. thank you.
0
 
JElsterAuthor Commented:
thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now