检索Image时,IsolatedStorageFileStream上不允许操作

时间:2012-06-19 03:41:26

标签: windows-phone-7

我无法理解为什么只有硬编码文件名工作?

1) Without hardcoding filename . Problems:  Operation not permitted on IsolatedStorageFileStream 

2) But when I hardcode the filename, say, "Test.jpg"  in SaveImageFile()  and GetImageInISO(),
   I can view the image and there is no error message.


 1---------- save an Image from ImageControl :

Private void SaveImageFile()
{

  string strImgFile = strCountry + strCity + ".jpg";

  using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
   {

     using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(strImgFile, FileMode.Create, store))
       {                         
          WriteableBitmap wb = new WriteableBitmap(g_IntWidth, g_IntHeight);
          wb.Render(cn, new TranslateTransform());
          wb.Invalidate();

      System.Windows.Media.Imaging.Extensions.SaveJpeg(wb, isfs, g_IntWidth, g_IntHeight, 0, 100);

      isfs.Close();                    

         }
    }

}


--2------------Read the image 

 private void GetImageInISO()
 {

     string strPassIn = strCountryName + strCityName + ".jpg";

     BitmapImage bmp = new BitmapImage();


  using (var store = IsolatedStorageFile.GetUserStoreForApplication())
   {

 using (IsolatedStorageFileStream isfs = store.OpenFile(strPassIn, System.IO.FileMode.Open,FileAccess.Read))

      {
           if (isfs.Length > 0)                           
             {                           
               bmp.SetSource(isfs);

                isfs.Close();
              }
             else
              {
                MessageBox.Show("Empty file");
               }                        
           }

       }
          image1.Width = bmp.PixelWidth;
           image1.Height = bmp.PixelHeight;
           image1.Source = bmp;
  }
}

1 个答案:

答案 0 :(得分:0)

谢谢大家。你的建议有帮助。文件名包含不应包含的空格字符。删除空格后,它可以正常工作。