如何將ImageSource設置爲來自特定文件夾的圖像?從特定文件加載圖像
我試圖移動在調試圖像和運行下面的代碼:
image.Source = new BitmapImage(new Uri("kafpodhlato.png"));
,但我得到了以下錯誤:
An unhandled exception of type 'System.UriFormatException' occurred in System.dll
Additional information: Invalid URI: The format of the URI could not be determined.
編輯:創建一個文件夾命名爲資源,設置它的Build action
到Resource
然後使用下面的代碼解決了我的問題。
image.Source = new BitmapImage(new Uri(@"pack://application:,,,/Resources/panamaxi.png"));
加載它? –