Log in

View Full Version : Loading embedded bitmaps from executable in C#


ricardomas
07-22-2004, 07:00 PM
I have written a C# app and I need to change the image for a PictureBox control on a form. I have created several bitmaps and have embedded them in the executable. I need to programmatically change the PictureBox image based on user input.

Can someone tell me how I can load those images from the executable into an Image or Bitmap object?

Thanks.

Kati Compton
07-22-2004, 07:19 PM
I'm afraid I don't know C#, but is there a "getResource()" type function?

ctitanic
07-22-2004, 08:52 PM
You can create one picturebox for each image and change the visible property of them depending of what you need.

humbletim
08-31-2004, 12:58 AM
I'm afraid I don't know C#, but is there a "getResource()" type function?

Yup -- here is a code snippet. It would be the same for new Bitmap instead of new Icon. What stumped me at first was that the resource name must be fully-qualified with the namespace and any subfolders (which in my case was "net.MobileLeap.Browser" and my icons are in a subfolder called "icons").


...

System.Reflection.Assembly assem = this.GetType().Assembly;

Icon m_icon = new Icon(assem.GetManifestResourceStream("net.MobileLeap.Browser.icons.question.ico"));

..


-t

ricardomas
08-31-2004, 05:03 AM
Great. Thanks for the help, it works beautifully.

Happy Computing!