当我创建一个bitmapimage列表时出现了OutOfmemory错误...
我应该做什么......?
感谢您的帮助;)
这是我的代码:
foreach (var bytearray in imageDataBlocksPresta)
{
if (bytearray != null)
{
MemoryStream ms;
using (ms = new MemoryStream(bytearray, 0, bytearray.Length))
{
BitmapImage photo = new BitmapImage();
photo.DecodePixelHeight = 800;
photo.DecodePixelWidth = 624;
photo.SetSource(ms);//ERROR
listphotoPresta.Add(photo);
}
}
else//si photo null
{
BitmapImage photo = new BitmapImage();
photo.DecodePixelHeight = 800;
photo.DecodePixelWidth = 624;
photo.UriSource = new Uri("/Images/NoImageIcon.jpg", UriKind.RelativeOrAbsolute);
listphotoPresta.Add(photo);
}
答案 0 :(得分:2)
尝试将照片设置为null并在添加后调用GC.Collect()。像这样:
listphotoPresta.Add(photo);
photo = null;
GC.Collect();
答案 1 :(得分:0)