Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / August 2006

Tip: Looking for answers? Try searching our database.

How to retrive an image from a resource file?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Patrick F - 14 Aug 2006 11:32 GMT
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?
Mini-Tools Timm - 14 Aug 2006 14:50 GMT
> 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();

Signature

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

Patrick F - 14 Aug 2006 15:40 GMT
thanks alot, works now

> > 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
[quoted text clipped - 21 lines]
>     // use this to get the names of all resources in your assembly
>     string [] resNames = a.GetManifestResourceNames();

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.