在“隔离存储”中加载和存储图像

时间:2014-01-07 11:54:53

标签: windows-phone-8

我正在开发一个应用程序,我从Web服务器下载图像,然后存储在独立存储中。但是,我在BI.SetSource(Str_ri.Stream);

收到错误

这是我的代码:

string name = "image" + current.ImageId;
   using (IsolatedStorageFile ISF = IsolatedStorageFile.GetUserStoreForApplication())
   {
      if (ISF.FileExists(name))
      {
      }
      else
      {
         IsolatedStorageFileStream filestream = ISF.CreateFile(name);
         StreamResourceInfo sr = null;
         Uri ur = new Uri(name, UriKind.Relative);
         sr = Application.GetResourceStream(ur);
         BitmapImage bi = new BitmapImage();
         bi.SetSource(sr.Stream);
         WriteableBitmap wr_B = new WriteableBitmap(bi);
         System.Windows.Media.Imaging.Extensions.SaveJpeg(wr_B, filestream, wr_B.PixelWidth, wr_B.PixelHeight, 0, 85);
         wr_B.SaveJpeg(filestream, wr_B.PixelWidth, wr_B.PixelHeight, 0, 85);
         filestream.Close();
      }
   }

1 个答案:

答案 0 :(得分:1)

我得到了答案。将bi.SetSource(sr.Stream);更改为bi.SetSource(filestream );如果您想要更多细节,请关注  how to store an image received from the web and display it in the windows phone 7 application