473,394 Members | 1,773 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,394 software developers and data experts.

How to retrive an image from a resource file?

Hi, i have a resourcefile with my project that contains a jepg image. Now i
want to retrive that image to a Image m_Image in my program. Whats the best
way to do this?
Aug 14 '06 #1
2 2304
"Patrick F" wrote:
Hi, i have a resourcefile with my project that contains a jepg image. Now i
want to retrive that image to a Image m_Image in my program. Whats the best
way to do this?
Assembly a = Assembly.GetExecutingAssembly();
Stream stream = a.GetManifestResourceStream( "MyNamespace.MyImage.jpg" );
if (stream != null)
{
this.m_Image = Bitmap.FromStream( stream ) as Bitmap;
stream.Close();
}

You have to ensure MyImage.jpg is included in your project and marked as an
"Embedded Resource" in its properties. In the example above, MyImage.jpg
must be located in the root project folder. If it's located in a subfolder,
such as "Art", you would need to add that to the path, using a period instead
of backslash, such as:

"MyNamespace.Art.MyImage.jpg"

If the image is not loading, you can confirm its existence and path in your
resource file by adding the following line to the code above:

// use this to get the names of all resources in your assembly
string [] resNames = a.GetManifestResourceNames();

--
Timm Martin
Mini-Tools
..NET Components and Windows Software
http://www.mini-tools.com

Aug 14 '06 #2
thanks alot, works now

"Mini-Tools Timm" wrote:
"Patrick F" wrote:
Hi, i have a resourcefile with my project that contains a jepg image. Now i
want to retrive that image to a Image m_Image in my program. Whats the best
way to do this?

Assembly a = Assembly.GetExecutingAssembly();
Stream stream = a.GetManifestResourceStream( "MyNamespace.MyImage.jpg" );
if (stream != null)
{
this.m_Image = Bitmap.FromStream( stream ) as Bitmap;
stream.Close();
}

You have to ensure MyImage.jpg is included in your project and marked as an
"Embedded Resource" in its properties. In the example above, MyImage.jpg
must be located in the root project folder. If it's located in a subfolder,
such as "Art", you would need to add that to the path, using a period instead
of backslash, such as:

"MyNamespace.Art.MyImage.jpg"

If the image is not loading, you can confirm its existence and path in your
resource file by adding the following line to the code above:

// use this to get the names of all resources in your assembly
string [] resNames = a.GetManifestResourceNames();

--
Timm Martin
Mini-Tools
.NET Components and Windows Software
http://www.mini-tools.com
Aug 14 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Priti Joshi | last post by:
I am writing one program to store and retrive the imaages in sql server by using c#. It gets stored but when I retrive the image file clearity is very much lost. So, could you please send me the...
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,...
6
by: Saya | last post by:
Hello, This is a repost 'cause I haven't solve the problem: I can't use the System.Drawing class 'Image.FromStream' in the CompactFramework environment. What I've done with respect to Brendan's...
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...
0
nehashri
by: nehashri | last post by:
hi, I need one help regarding Asp with MsAccess database. Problem. ======== i want to retrive stored image from the MSAccess database using asp.
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...
1
by: amritranjan | last post by:
How to retrive image file from MS access database and display this in another JSPpage -------------------------------------------------------------------------------- This is my Jsp code for...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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.