【问题标题】:Storing photos in isolated storage and reading mutiple photos with out memory consumption将照片存储在隔离存储中并读取多张照片而不会消耗内存
【发布时间】:2011-05-08 14:40:14
【问题描述】:

我将用户的照片存储在独立存储中并在列表框中显示它们。我使用以下代码从隔离存储中检索图像

        BitmapImage bi = new BitmapImage(); 
        var isoFile = IsolatedStorageFile.GetUserStoreForApplication(); 
        if (isoFile.FileExists(imageFileName)) 
        {
            using (var imageStream = isoFile.OpenFile( 
                imageFileName, 
                FileMode.Open, FileAccess.Read)) 
        {
        //imageSource = PictureDecoder.DecodeJpeg(imageStream); 
        bi.SetSource(imageStream); 
    }
}
isoFile.Dispose();
//return imageSource; 
return bi; 

存储了100张图像。每次加载图像时,内存消耗不断增加,然后内存耗尽。有没有更好的方法来访问内存消耗更少的图像。即使在加载结束时我也使用了GC.Collect()。它根本不起作用。

有没有更好的方法从隔离存储中读取和读取图像?

我让我的用户将照片保存在隔离存储中。就我而言,隔离存储是更好的选择吗?

【问题讨论】:

  • 您希望同时显示多张图片,还是一次只显示一张?
  • 一次加载的一组图像
  • 所有图片一旦加载就会解压,所以它们的内存占用非常大。另外,您是重用图像控件来显示图像还是创建新图像?不要忘记将位图图像设置为 null 以删除它们。
  • 我有一个列表框。我将位图绑定到图像标签。 不知道在哪里处理它..

标签: windows-phone-7 isolatedstorage


【解决方案1】:

Stefan Wick 在他的博客 http://blogs.msdn.com/b/swick/archive/2011/04/07/image-tips-for-windows-phone-7.aspx

上提供了一些关于处理图像的绝妙技巧,包括如何避免过度的内存消耗

你只需要强制设置Image和内部BitmapImage为null,当你完成图像时释放内存。

BitmapImage bitmapImage = image.Source as BitmapImage;
bitmapImage.UriSource = null;
image.Source = null;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-09
    • 2019-08-08
    相关资源
    最近更新 更多