2014-03-29 52 views
1

我需要從Microsoft.Xna.FrameWork.Media.Picture中保存圖像的路徑,然後在代碼的其他部分加載此路徑到BitmapImage,然後顯示出來。 Uri保存很好,但我無法弄清楚爲什麼圖像沒有加載。Windows phone 8從本地路徑加載圖像

//Gt uri of image. I try this withnout UriKind too. 
//AbsoluteUri is: file:///C:/Data/Users/Public/Pictures/Sample%20Pictures/sample_photo_00.jpg 
//LocalPath is: C:\Data\Users\Public\Pictures\Sample Pictures\sample_photo_00.jpg 
uri = new Uri(picture.GetPath(), UriKind.Absolute); 


//Create BitmapImage from Uri. 
BitmapImage image = new BitmapImage(photo.Url); 

如果我改變加載圖像:

image = new BitmapImage(new Uri("someInternetAdress")); 

It's加載確定。

謝謝你的幫助!

回答

0

試試這個方法:

Uri uri = new Uri(picture.GetPath(), UriKind.Relative); 
StreamResourceInfo resourceInfo = Application.GetResourceStream(uri); 
BitmapImage image = new BitmapImage(); 
image.SetSource(resourceInfo.Stream); 
+0

這是行不通的,它仍然進行同樣的操作。但是,謝謝你的興趣幫助我 – Lenny

+0

你能多解釋一下嗎?你是什​​麼意思,它不是加載,任何錯誤,或只是沒有發生? – Cyral

+0

沒有錯誤。當我使用組件Image來展示這個,所以沒有高手,但是如果我使用互聯網網址的話。 – Lenny