Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Loading an embedded bitmap in C#

252 views
Skip to first unread message

Ted Williams

unread,
Apr 22, 2004, 5:05:37 PM4/22/04
to
Hi,

I have a question: How do you load an embedded bitmap resource in C#? I
have tried the following but it doesn't seem to want to work:

Module mod = Assembly.GetExecutingAssembly().GetModules()[0];
IntPtr hInst = Marshal.GetHINSTANCE( mod );
bmToolbox = Bitmap.FromResource( hInst, "Toolbox.bmp" );

Please let me know the proper way to do this. I know I must be missing
something as this whole method seems round about to me.

Thanks,
Ted

Bob Powell [MVP]

unread,
Apr 22, 2004, 5:53:00 PM4/22/04
to
Bitmap
bm=(Bitmap)Image.FromStream(this.GetType().Assembly.GetManifestResourceStrea
m(<full name of resource>));

The Windows Forms Tips and Tricks page has an article on the ToolboxBitmap
which shows how to locate a resource in the assembly. This will help you to
understand how the fully qualified name works.

http://www.bobpowell.net.tipstricks.htm


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

All you ever wanted to know about ListView custom drawing is in Well Formed.
http://www.bobpowell.net/currentissue.htm

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

Subscribe to the RSS feed at http://bobpowelldotnet.blogspot.com
to get notifications of all new GDI+ FAQ articles and Windows Forms Tips and
Tricks

"Ted Williams" <twil...@video-mation.com> wrote in message
news:OO72Q2K...@TK2MSFTNGP11.phx.gbl...

coder191

unread,
Apr 22, 2004, 9:51:03 PM4/22/04
to
hi,
Another way is to save the image into a folder in the file system:
//if the file not exist
image1.Save(context.Server.MapPath(string.Concat(directory, "\",imagename)), ImageFormat.Jpeg);
Then in your app, point the control to the image.
This way you only need to extract the binary stream once => better performance.

Rgds
*****http://www.smartcodeworks.com*******************************************
Find the webcontrols(Image Manager,calendar,Twinlist,outputmanager),Generic DB tools, free download and useful articles
***************************************************************************

----- Bob Powell [MVP] wrote: -----

Paul Wardle

unread,
Apr 23, 2004, 5:29:42 PM4/23/04
to
What about

Bitmap b = new Bitmap(typeof(myClass), "mybitmap.bmp");

include the bmp as an embedded resource in the same project as myclass.

Paul


"Ted Williams" <twil...@video-mation.com> wrote in message
news:OO72Q2K...@TK2MSFTNGP11.phx.gbl...

0 new messages