需要添加引用命名空间
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); }; }
}