How to get image from a folder path in wpf

后端 未结 3 418
天命终不由人
天命终不由人 2021-01-21 00:17

I\'m trying to understand how to make a get a file from my project I\'m using visual studio 2010, and I have a folder in my wpf project that is called: Images

How can I

相关标签:
3条回答
  • 2021-01-21 01:00

    you can look at something like this

    string imageName = name + ".jpg";
    var path = Path.Combine(GetApplicationFolder(), "/Images/" + imageName);
    

    if you want to find it via the Assembly you could use the following as well

    var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
    
    0 讨论(0)
  • 2021-01-21 01:07

    I think your problem is that the relative path, at least from the code we can see, is relative to the output exe file. I doubt this folder is bin>debug or bin>release. So you would need to go back a certain number of directories (hopes). This article explains relative paths very well.

    EDIT:

    Unless you have custom compiling option enabled, then you are incorrectly referencing the relative path. Have a look the above link, please.

    Hope this helps you!

    0 讨论(0)
  • 2021-01-21 01:08

    what about

    var uriSource = new Uri(@"/FinalSadna;component/imagename.png", UriKind.Relative);
    
    0 讨论(0)
提交回复
热议问题