内存溢出异常,而从独立存储加载图像 [英] Out of memory exception while loading images from isolated storage

查看:143
本文介绍了内存溢出异常,而从独立存储加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到的 OutOfMemoryException异常 的在这个特殊的代码。

I am getting OutofMemoryException in this particular code.

public BitmapImage GetImage(int pageNo)
        {
            if (!this._isLoaded)
            {
                this.Load();
            }
            using (IsolatedStorageFileStream stream = IsolatedStorageFile.GetUserStoreForApplication().OpenFile(this.FileNames[pageNo], FileMode.Open, FileAccess.Read))
            {
                BitmapImage image = new BitmapImage();
                image.SetSource(stream);            

                return image;

            }
        }



该内存不足的异常是发生在 image.SetSource(流)。我不能设置URI来,因为我要返回到图像显示。

The out of memory exception is occuring at image.SetSource(stream) . I cant set the uri to null because I have to return the image.

,这是什么解决办法?在这里帮我。

What is the workaround for this? Help me here.

推荐答案

我有位图图像列表中。

 private List<BitmapImage> _images = new List<BitmapImage>();



我清除了URI而离开页面。

I cleared the uri while leaving the page.

 protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);
            this.DataContext = null;
            foreach (var obj in this._images)
            {
                if (obj != null)
                {
                    obj.ClearValue(BitmapImage.UriSourceProperty);
                }

            }

这篇关于内存溢出异常,而从独立存储加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆