【发布时间】:2015-08-28 00:01:41
【问题描述】:
我想做的是在我的应用中为我的用户维护个人资料图片。 用户可以从本地图片库中获取图片。因此,每当应用程序加载时,它应该检查本地应用程序数据是否存在图片,如果存在,它应该将图像设置为它。我试过这样做,但它不起作用。
// Saving
BitmapImage bitmapImage = image.Source as BitmapImage;
Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
string path = bitmapImage.UriSource.ToString();
localSettings.Values["ProfilePic"] = path;
// In constructor retrieving like this.
string sourceVal = localSettings.Values["ProfilePic"] as string;
if (sourceVal != null) {
Image img = new Image();
BitmapImage bi = new BitmapImage();
Uri uri = new Uri(sourceVal);
bi.UriSource = uri;
img.Source = bi;
}
它正在抛出异常,任何人都可以使用 C# 给他们适当的代码吗?
System.NullReferenceException 发生。
【问题讨论】:
-
错误发生在哪一行?
标签: c# windows windows-phone-8