最近做的wpf項目中,在開發的時候,把圖片放到了bin下面,采用了imagePath =System.IO.Directory.GetCurrentDirectory()+"/images/starShow.jpg";獲得圖片是可以的,可是發布之后卻獲取不到圖片,這讓我很糾結,后來通過把圖片添加到了資源中,然后調用資源即可解決了問題
imagePath = "pack://application:,,,/Financial;component/Properties/../images/star/starShow.jpg";
imageBrush.ImageSource = new BitmapImage(new Uri(imagePath, UriKind.RelativeOrAbsolute));
imageBrush.Stretch = Stretch.Fill;//設置圖像的顯示格式
btn.Background = imageBrush;