473,659 Members | 3,592 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2313
"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.GetExe cutingAssembly( );
Stream stream = a.GetManifestRe sourceStream( "MyNamespace.My Image.jpg" );
if (stream != null)
{
this.m_Image = Bitmap.FromStre am( 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.Ar t.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.GetManifestRe sourceNames();

--
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.GetExe cutingAssembly( );
Stream stream = a.GetManifestRe sourceStream( "MyNamespace.My Image.jpg" );
if (stream != null)
{
this.m_Image = Bitmap.FromStre am( 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.Ar t.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.GetManifestRe sourceNames();

--
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
1222
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 code of doing this.
4
1935
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 displayed. How can I force the compiler to re-link to that gif file on the file system at compile time so that I don't need to re-assign the gif file every time a change is made to it? thanks!
1
3840
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, string tables, etc.) and place them into a imagelist. I have found examples using the resource manager to create a "resource file" like so: ResourceWriter rw = new ResourceWriter (
6
8557
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 suggestion is as follows: Brendan, thanks for the reply! I'm a little bit further now, but not yet finished. I've come this far, see code below: Stream s =
5
3377
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 -- Message posted via DotNetMonster.com
3
12118
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 in the get resource code. The code I'm using is: System.Reflection.Assembly myAssembly; myAssembly = this.GetType().Assembly;
0
1606
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
2961
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 these forms have a save button with an icon (along with other common buttons and icons). At this point, we've added the icon to each project. Unfortunately, if we want to change the icon, we now have to go to every project and change it. It would...
1
2982
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 image upload in database: -----------Upload.jsp---------------- <html> <head> <title>Account Details </title>
0
8337
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8628
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2754
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.