我正在尝试使用以下代码将 XAP 中的多个图像文件保存到隔离存储中。我计划保存大约 100 个文件。问题是线路
sri = Application.GetResourceStream(uri)
中途返回 null。模拟器可以保存的文件数量有限制吗?或者可能是我错过了什么..
private static void SaveImageFileToIsoStore()
{
string[] files = AllFilesInImagesCatFolder();
using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!isoStore.FileExists(files[0]))
{
foreach (string f in files)
{
IsolatedStorageFileStream fileStream = isoStore.CreateFile(f);
StreamResourceInfo sri = null;
Uri uri = new Uri("Images/cat/" + f, UriKind.Relative);
Debug.WriteLine(f);
sri = Application.GetResourceStream(uri);
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(sri.Stream);
WriteableBitmap wb = new WriteableBitmap(bitmap);
// Encode WriteableBitmap object to a JPEG stream.
Extensions.SaveJpeg(wb, fileStream, wb.PixelWidth, wb.PixelHeight, 0, 100);
fileStream.Close();
fileStream.Dispose();
}
}
}
}