2014-01-24 42 views
0

我想分享圖像。我得到了一個圖片對象,並從中獲取路徑。當我打電話給ShareMediaTask時,拋出以下錯誤:Windows Phone 8 ImageSource無法序列化共享圖像時出錯

System.Windows.Media.ImageSource不能被序列化。

我仍然可以分享圖像,但應用程序從共享返回時崩潰。

這裏是我的代碼:

 PictureModel picture = Singleton.Instance.BearPicture.Model.Images.Where(PictureModel => PictureModel.Bmp.UriSource == (Image_View.Source as BitmapImage).UriSource).FirstOrDefault(); 


     var task = new ShareMediaTask(); 


     task.FilePath = picture.Picture.GetPath(); 

     task.Show(); 

我PictureModel看起來是這樣的:

public class PictureModel : INotifyPropertyChanged 
{ 
    public event PropertyChangedEventHandler PropertyChanged; 

    private string _uri; 
    public string Uri 
    { 
     get { return _uri; } 
     set 
     { 
      if (value != _uri) 
      { 
       _uri = value; 
       NotifyPropertyChanged("Uri"); 
      } 
     } 
    } 

    private string _relativePath; 
    public string RelativePath 
    { 
     get { return _relativePath; } 
     set 
     { 
      if (_relativePath != value) 
      { 
       _relativePath = value; 
       NotifyPropertyChanged("RelativePath"); 
      } 
     } 
    } 

    private BitmapImage _bmp; 
    public BitmapImage Bmp 
    { 
     get { return _bmp; } 
     set 
     { 
      if (value != _bmp) 
      { 
       _bmp = value; 
       NotifyPropertyChanged("Bmp"); 
      } 
     } 
    } 

    private Picture _picture; 
    public Picture Picture 
    { 
     get { return _picture; } 
     set 
     { 
      if (value != _picture) 
      { 
       _picture = value; 
       NotifyPropertyChanged("Picture"); 
      } 
     } 
    } 

    private void NotifyPropertyChanged(string propertyName) 
    { 
     if (PropertyChanged != null) 
     { 
      PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 
     } 

    } 

} 

哪裏從何而來這個錯誤?我只得到我的圖像對象的來源,但我沒有做任何其他事情。我的照片也被保存在媒體庫中像這樣:

myFileStream = myStore.OpenFile(fileName, FileMode.Open, FileAccess.Read); 
      MediaLibrary library = new MediaLibrary(); 
      Picture pic = library.SavePicture(fileName, myFileStream); 

在AppStart的IM通過我savedpicture文件夾進行搜索,得到的圖片對象,然後將其保存在我的PictureModel。

任何幫助表示讚賞。 在此先感謝。 robidd

回答

1

這可能有所幫助:Crashes Back (WriteableBitmap cannot be serialized) windows phone 8。查看來自KooKiz的評論。 「

」相同的症狀,相同的原因。您已經在某個時間點存儲了手機狀態下的ImageSource(可能是PhoneApplicationService.Current.State或IsolatedStorageSettings.ApplicationSettings),您必須找到位置!

顯然我們可以間接導致這個錯誤。我有類似的問題,我找到了答案,也是你自己的問題。

希望它有幫助。 乾杯。

相關問題