WP开发图片保存到独立存储并从独立存储中读取

需要添加引用命名空间

using System.IO;

using System.IO.IsolatedStorage;

1.将图片保存到独立存储空间

 using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())

             {

                 if (myIsolatedStorage.FileExists(App.fileName))

                 {

                     myIsolatedStorage.DeleteFile(App.fileName);

                 }

                 using(IsolatedStorageFileStream fileStream = myIsolatedStorage.CreateFile(App.fileName))

                 {

                     BitmapImage bitmap = new BitmapImage();

                     bitmap.SetSource(stream);

                     WriteableBitmap wb = new WriteableBitmap(bitmap);

                     // Encode WriteableBitmap object to a JPEG stream.

                     wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, , );

                 }

             }

         }

2.从独立存储空间中获取图片

 using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())

                 {

                     if (myIsolatedStorage.FileExists(fileName))

                     {

                         using (IsolatedStorageFileStream fileStream = myIsolatedStorage.OpenFile(fileName, FileMode.Open, FileAccess.Read))

                         {

                             BitmapImage bmp = new BitmapImage();

                             bmp.SetSource(fileStream);

                         };

                       }
}
上一篇:C#不同窗体间通信,数据传递


下一篇:理解CSV文件以及ABAP中的相关操作