CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2009
    Posts
    3

    setting image source

    hi, i am trying to set an image source without giving the full path. It works only with this code:
    Uri uri = new Uri("C:/Documents and Settings/user/My Documents/Visual Studio 2008/Projects/player/poze/open1.jpg");
    ImageSource imgSource = new System.Windows.Media.Imaging.BitmapImage(uri);
    img_open.SetValue(Image.SourceProperty, imgSource);

    But, if i try to run the application on other computers, it doesn't load the image, and it's obvious.

    i tried to do somethig like this:
    System.Environment.CurrentDirectory = "C:/Documents and Settings/user/My Documents/Visual Studio 2008/Projects/player/poze/";
    and then run the code:
    Uri uri = new Uri("open2.jpg",UriKind.Relative);
    ImageSource imgSource = new System.Windows.Media.Imaging.BitmapImage(uri);
    img_open.SetValue(Image.SourceProperty, imgSource);
    but it doesn't work.
    any suggestions?

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: setting image source

    Add the image as an embedded resource to your project. Right click project -> properties -> resources -> add existing item.

  3. #3
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Re: setting image source

    If you have a lot of very large images, you may wish to check out the System.Environment.SpecialFolder enumeration.

    Specifically:
    Code:
    Environment.GetFolderPath(Environment.SpecialFolder....)
    Last edited by rliq; August 24th, 2009 at 09:45 PM.
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured