簡體   English   中英

將URI設置為圖像源應用程序中的根目錄

[英]Setting URI to root directory in application for image source

如何在WPF應用程序中將圖像源的URI設置到根目錄(即與exe相同的文件夾)?

var myImage = new Image();
myImage.Source = new BitmapImage(new Uri("pack://application:,,,/AssemblyName;component/speedline.png", UriKind.Absolute));

我已經嘗試了上述方法,並不斷收到以下錯誤消息:

mscorlib.dll中發生了'System.IO.FileNotFoundException'類型的未處理異常。 附加信息:無法加載文件或程序集'AssemblyName,Culture = neutral'或其依賴項之一。 該系統找不到指定的文件。

我顯然做錯了什么,但可以保證png文件可以在exe文件所在的文件夾中的C:\\Users\\Admin\\Documents\\Visual Studio 2013\\Projects\\Speedy\\Speedy\\bin\\Debug中找到,但是我該如何引用呢?

在稱為組件的解決方案資源管理器下創建一個新文件夾,並在該文件夾下添加現有圖像。 現在嘗試使用相對路徑。

myImage = new BitmapImage(new Uri("/component/speedline.png", UriKind.Relative));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM