我正在开发一个 Windows 手机应用程序,我正在从媒体库中收集图像并将每个项目添加到列表框。这是我的代码....
public MainPage()
{
InitializeComponent();
getImages();
}
public void getImages()
{
try
{
MediaLibrary mediaLibrary = new MediaLibrary();
var pictures = mediaLibrary.Pictures;
foreach (var picture in pictures)
{
BitmapImage image = new BitmapImage();
image.SetSource(picture.GetImage());//out of memory exception
img mediaImage = new img();
mediaImage.Imgs = image;
imageList.Items.Add(mediaImage);
}
}
catch (Exception ex)
{
}
}
public class img
{
public img()
{ }
public BitmapImage Imgs { get; set; }
}
在 Xml...
<ScrollViewer Name="sc" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Hidden" Margin="0,422,0,43">
<ListBox Name="imageList" SelectionChanged="imageList_SelectionChanged_1" Height="126">
<ListBox.ItemsPanel>
<ItemsPanelTemplate >
<StackPanel Orientation="Horizontal"></StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate >
<StackPanel Orientation="Horizontal">
<Image Margin="10" Name="image1" Source="{Binding Imgs}" Height="150" Width="150"></Image>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</ScrollViewer>
当我加载此列表框时,我在 Picture.GetImage() 中出现内存不足异常,我已用代码编写。请告诉我如何释放内存。