WPF Image.Source 什么都不做

杰克·格雷

我一直在尝试将后面的代码中Image.Source设置为这样的相对路径:

IMG_3.Source = new BitmapImage(new Uri("./Sprites/Layout/image1.png", UriKind.Relative));

如果我使用不存在的路径,程序就会崩溃。

但是这条路径存在并且就像一个.Fill in a Rectangle 一样工作。这里有什么问题吗?

用户7220101

我看这里没有任何问题。请尝试使用完整路径。.Last()是 Linq,所以如果你不想使用它,只需用 count - 1 做同样的事情。

string exe = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName.Split('\\').Last();
IMG_3.Source = new BitmapImage(new Uri(System.Reflection.Assembly.GetExecutingAssembly().Location.Substring(0, System.Reflection.Assembly.GetExecutingAssembly().Location.Length - exe.Length) + "/Sprites/Layout/image1.png"));

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章