我已将近 150 张高分辨率图像存储到独立存储中,分辨率为 789x 1299。我的问题是,当我将 60 - 70 个图像加载到列表集合中时,它工作正常,但是当 bi.SetSource(ms) 中发生超过 70 个内存不足异常时。我在项目模板中使用虚拟化 satck 面板。什么原因
List<SampleData> data = new List<SampleData>();
try
{
for (int i = 0; i < 150; i++)
{
byte[] data2;
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isfs = isf.OpenFile("IMAGES" + i + ".jpg", FileMode.Open, FileAccess.Read))
{
data2 = new byte[isfs.Length];
isfs.Read(data2, 0, data2.Length);
isfs.Close();
}
}
MemoryStream ms = new MemoryStream(data2);
BitmapImage bi = new BitmapImage();
bi.SetSource(ms);
data.Add(new SampleData() { Name = bi });
}
this.list.ItemsSource = data;
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
public class SampleData
{
public ImageSource Name
{
get;
set;
}
}
}
}
<ListBox x:Name="list" Width="480">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="10">
<Image Height="500" Width="500" Source="{Binding Name}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel VirtualizingStackPanel.VirtualizationMode="Recycling" Orientation="Vertical"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>