【发布时间】:2011-05-06 20:06:08
【问题描述】:
嘿。 当用户单击这样的项目时,我正在从独立存储中读取图像:
using (IsolatedStorageFile currentIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (var img = currentIsolatedStorage.OpenFile(fileName, FileMode.Open))
{
byte[] buffer = new byte[img.Length];
imgStream = new MemoryStream(buffer);
//read the imagestream into the byte array
int read;
while ((read = img.Read(buffer, 0, buffer.Length)) > 0)
{
img.Write(buffer, 0, read);
}
img.Close();
}
}
这很好用,但是如果我在两个图像之间来回单击,内存消耗会不断增加,然后内存不足。有没有更有效的方式从独立存储中读取图像?我可以在内存中缓存几张图片,但有数百个结果,最终还是会占用内存。有什么建议吗?
【问题讨论】:
-
除非我遗漏了什么,否则您上面的代码实际上并没有对 imgStream 做任何事情
-
抱歉,返回了imgStream。上面的代码在一个返回 MemoryStream 的方法中。
标签: c# memory-management windows-phone-7 isolatedstorage