开发者

Problem with image path [C#, WPF]

开发者 https://www.devze.com 2023-01-25 22:08 出处:网络
I need use images in 2 .NET assemblies. One is WPF app {myApp.exe} and second is *.dll {myDll.dll}.File are 开发者_C百科located in this file structure:

I need use images in 2 .NET assemblies. One is WPF app {myApp.exe} and second is *.dll {myDll.dll}. File are 开发者_C百科located in this file structure:

 **AppFolder** consist these files and one subfolder(avatars):

    -myApp.exe
    -myDll.dll
    -avatars {folder} consist:
          -manImages.jpg
          -womanImages.jpg

I try user uri in this format

new Uri(@"C:\Users\avatars\manImages.jpg", UriKind.RelativeOrAbsolute);

but this format does not work, images are empty.


I would expect

new Uri(@"avatars\manImages.jpg", UriKind.RelativeOrAbsolute);

to work?

You could also try:

new Uri(Environment.CurrentDirectory + @"\avatars\manImages.jpg", UriKind.RelativeOrAbsolute);


On the dll side you can write this:

string imgPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "avatars\\manImages.jpg");
0

精彩评论

暂无评论...
验证码 换一张
取 消