Windows phone 7 从流设置位图图像源时出现后台调度内存不足异常

Windows phone 7 从流设置位图图像源时出现后台调度内存不足异常,windows-phone-7,windows-phone-8,Windows Phone 7,Windows Phone 8,我想定期更新翻转平铺图像,以便添加ScheduledAgent项目,并尝试将图像保存在隔离共享文件夹中的固定路径中。但是当我从图像流设置位图图像源时,内存不足异常 这是密码 using (var isoFile = IsolatedStorageFile.GetUserStoreForApplication()) { const string filePath = @"Shared\ShellContent\FlipBackImage.jpg";

我想定期更新翻转平铺图像,以便添加
ScheduledAgent
项目,并尝试将图像保存在
隔离共享文件夹中的固定路径中。但是当我从
图像流
设置
位图图像
源时,内存不足异常

这是密码

    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));
        }
每次尝试设置分辨率为1500x1100
图像时,我都会遇到异常,即使它的大小只有
29 kb

如何处理此问题?

iso.Close()


在图像流读取完成后写入此命令

图片为29kb的压缩格式。当加载到
BitmapImage
中时,需要对其进行解码,并且每像素将使用4个字节(每种颜色一个字节,加上alpha通道)。这使得1500 x 1100 x 4=6600000字节=大约6.5 MB。一个后台代理只能使用10MB的RAM,因此只有图片使用了65%的可用内存。添加加载应用程序所需的内存,您就拥有了它。在WP8上,您可以使用
BitmapImage
DecodePixelWidth
DecodePixelHeight
属性来避免在内存中解码整个图片(因为您无论如何都会调整它的大小):不幸的是,据我所知,你不能设置这些属性WP7@KooKiz谢谢你的回答。但对于3MB大小的图像仍然存在问题。我有一个相同的问题:(基本上,您不能在后台代理中加载大于1280x768的位图图像,因为它会抛出OfMemoryException。