当我将类型 BitmapImage 添加到我的Windows 8 应用程序(如下)的类中时,我得到:
Cannot serialize member vehicleImage' of type 'Windows.UI.Xaml.Media.Imaging.BitmapImage', see inner exception for more details.
内部异常详细信息:
System.Runtime.InteropServices.WindowsRuntime.RuntimeClass is inaccessible due to its protection level. Only public types can be processed.
代码:
public BitmapImage vehicleImage
{
get
{
return m_vehicleImage;
}
set
{
Uri _baseUri = new Uri("ms-appx:///");
BitmapImage imageBitmap = new BitmapImage(new Uri(_baseUri, ImagePath));
m_vehicleImage = imageBitmap;
OnPropertyChanged("vehicleImage");
}
}
private async void SetImage()
{
var file = await Windows.Storage.KnownFolders.PicturesLibrary.GetFileAsync(ImagePath);
var fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
var img = new BitmapImage();
img.SetSource(fileStream);
vehicleImage = img;
}
我正在将对象序列化为 XML。当我删除这段代码时,一切正常。我希望能够拥有用户从他们的计算机中选择的图像(这就是我尝试使用 BitmapImage 类型的原因)。
任何帮助表示赞赏。