473,395 Members | 1,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 4254
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Roman Kagan | last post by:
Hi everyone, I am successful in retrieving the image from the table (.TIF), however, the retrieved file does not work. It looks like an image file - extension, size and all, but the image is not...
4
by: Matthew Wieder | last post by:
I have a form which contains a picturebox control which displays a gif image. By default, the image that was selected when I designed the dialog gets stored in the resx file and gets compiled and...
1
by: D. Yates | last post by:
Hi, I am looking for an example of how to extract bitmap images from an embedded resource file (a file with *.res extension, which can be viewed inside of the ide and can hold bitmaps, icons,...
7
by: Robert W. | last post by:
I think I'm going insane, but thought I'd check with you all first before I get myself commited! Here's a method I've built to retrieve an image: public static Image GetImage(string...
6
by: Dean Slindee | last post by:
Does anybody have an actual example of retrieving an Image data type column from a SQL Server table using a dataset (not a datareader)? I would like to see the statements that would move the...
5
by: aiki727 via DotNetMonster.com | last post by:
Hello everyone, Where do I store a bitmap or jpeg that I am using for a forms background image when I deploy the application? Or do I link these files to the app during the deployment? Thanks...
3
by: UJ | last post by:
I've got an image I want to embed in a dll to use on a screen later. I've got it in a resource file, got it to compile in to the dll. The problem is getting it back out. It seems like my problem is...
3
by: bbrewder | last post by:
I am interested in hearing how other people have handled sharing resources in multiple projects (for example, a save icon). We have a product that has many forms within many projects. Many of...
2
by: shivapadma | last post by:
i have inserted the image into database using the following code String driverName = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost:3306/"; String dbName =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.