471,348 Members | 1,285 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

Retrieving an Image from a resource file

I'm using VS2k5 and i've added a bunch of images to the project's
resource.resx file and thus they reside in the Resources folder. I want to
dynamically add an image to my project. I have no problem adding an image
if its part of an existing UserControl or Form, but just as part of the
general project, I can't seem to figure out how to obtain the info via the
ComponentResourceManager.

Thanks in advance.

dh
Jan 21 '06 #1
1 4133
Find the correct resource imageName looking at your assembly Manifest (use
ildasm), then try this...

public Bitmap getBitmap( string imageName, t
AnyTypeWithinTheSameAssemblyNamespace ) {

Assembly myAssembly = Assembly.GetAssembly(t);

Stream myStream = myAssembly.GetManifestResourceStream( t, imageName );

Bitmap b = new Bitmap(myStream, true);

myStream.Close();

// Get the current desktop screen graphics.

Graphics g = Graphics.FromHwnd(IntPtr.Zero);

// Make a bitmap using that color depth.

Bitmap bitmap = new Bitmap(b.Width, b.Height, g);

// Clean up.

g.Dispose();
// Start drawing on our new bitmap.

g = Graphics.FromImage(bitmap);

// Copy the loaded bitmap to the bitmap with proper screen depth.

g.DrawImage(b, 0, 0, bitmap.Width, bitmap.Height);

// Clean up.

g.Dispose();

b.Dispose();
return bitmap;

}

"Doug Handler" <dk*******@yahoo.com> wrote in message
news:OV**************@tk2msftngp13.phx.gbl...
I'm using VS2k5 and i've added a bunch of images to the project's
resource.resx file and thus they reside in the Resources folder. I want
to dynamically add an image to my project. I have no problem adding an
image if its part of an existing UserControl or Form, but just as part of
the general project, I can't seem to figure out how to obtain the info via
the ComponentResourceManager.

Thanks in advance.

dh

Jan 21 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Matthew Wieder | last post: by
1 post views Thread by D. Yates | last post: by
7 posts views Thread by Robert W. | last post: by
5 posts views Thread by aiki727 via DotNetMonster.com | last post: by
3 posts views Thread by UJ | last post: by
3 posts views Thread by bbrewder | last post: by
1 post views Thread by Ronak mishra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.