C# 从独立存储加载图像时出现内存不足异常
在这个特定的代码中,我得到了C# 从独立存储加载图像时出现内存不足异常,c#,windows-phone-7,out-of-memory,bitmapimage,C#,Windows Phone 7,Out Of Memory,Bitmapimage,在这个特定的代码中,我得到了OutofMemoryException public BitmapImage GetImage(int pageNo) { if (!this._isLoaded) { this.Load(); } using (IsolatedStorageFileStream stream = IsolatedStorageFile.G
OutofMemoryException
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(stream)
。我无法将uri设置为null
,因为我必须返回图像
解决这个问题的方法是什么?帮帮我。我有这个位图图像列表
private List<BitmapImage> _images = new List<BitmapImage>();
请尝试中的解决方案,因为您可以在初始化流之前关闭它。我找不到位图图像的BeginInit、CacheOption、EndInit属性。我这样做是为了wp 7。图像有多大?@antonizikov 1060x1500是图像的分辨率。在第一次呼叫时发生吗?我的意思是,工作流程是什么?您是否创建此图像一次?
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);
}
}