我想定期更新 Flip Tile Back Image,以便添加ScheduledAgent
Project 并尝试将图像保存在内部的固定路径中isolated Share Folder
。但是当我设置BitmapImage
Source from时出现内存不足异常Image Stream
。
这是代码
using (var isoFile = IsolatedStorageFile.GetUserStoreForApplication())
{
const string filePath = @"Shared\ShellContent\FlipBackImage.jpg";
var filename = "Image.png";
var stream = !isoFile.FileExists(filename) ? null : isoFile.OpenFile(filename, FileMode.Open, FileAccess.Read);
if (stream != null)
{
if (isoFile.FileExists(filePath))
{
isoFile.DeleteFile(filePath);
}
Debug.WriteLine("currentMemory"+DeviceStatus.ApplicationCurrentMemoryUsage);
var bi = new BitmapImage();
bi.CreateOptions = BitmapCreateOptions.None;
bi.SetSource(stream); //out of memory exception getting here
var wbm=new WriteableBitmap(bi);
using (var streamFront = isoFile.OpenFile(filePath, FileMode.Create))
{
wbm.SaveJpeg(streamFront, 691, 336, 0, 80);
}
Deployment.Current.Dispatcher.BeginInvoke(() => Utils.DisposeImage(wbm));
}
每次尝试设置一个甚至它的大小Image
时都会出现异常。
如何处理?Resolution 1500x1100
29 kb