Windows phone 8从本地路径加载图像

时间:2014-03-29 00:45:47

标签: .net windows-phone-8 xna

我需要从Microsoft.Xna.FrameWork.Media.Picture保存图像路径,然后在代码的其他部分加载此路径到BitmapImage然后显示。 Uri保存很好,但我无法弄清楚为什么图像没有加载。

//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"));

加载正常。

谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

试试这个方法:

Uri uri = new Uri(picture.GetPath(), UriKind.Relative);
StreamResourceInfo resourceInfo = Application.GetResourceStream(uri);
BitmapImage image = new BitmapImage();
image.SetSource(resourceInfo.Stream);
相关问题