Minimize memory consumption in the form of an image list (WPF)

I have a list that binds to an ObservableCollection and accepts a file name for displaying images enter image description here

My xaml:

<Window x:Class="ThumbnailsView.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="578" WindowStartupLocation="CenterScreen"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="55"/> </Grid.RowDefinitions> <ListBox Grid.Row="0" x:Name="ImageListbox" ItemsSource="{Binding}" Background="AliceBlue" ScrollViewer.HorizontalScrollBarVisibility="Disabled"> <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <CheckBox Height="16" VerticalAlignment="Top" Margin="0,10,0,0"/> <Image Margin="10,10,10,0" Height="64" Width="64" VerticalAlignment="Top"> <Image.Source> <BitmapImage DecodePixelWidth="64" UriSource="{Binding Path=Name}"/> </Image.Source> </Image> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> <ListBox.ItemsPanel> <ItemsPanelTemplate> <WrapPanel/> </ItemsPanelTemplate> </ListBox.ItemsPanel> </ListBox> <Button Grid.Row="1" Content="Get Images" Name="getImageBtn" Click="getImageBtn_Click" Width="100" Height="30"></Button> </Grid> </Window> 

The problem is that it uploads whole images and will consume a lot of rams if I have a large collection. How to minimize memory consumption?

+6
source share
3 answers

Enable user interface virtualization. Then the user interface controls will be redesigned and the minimum amount of memory will be used.

You can also upload a palette instead of full-fledged photos.


Some resources to read:

http://www.codeproject.com/Articles/34405/WPF-Data-Virtualization https://stackoverflow.com/questions/14456075/how-to-enable-ui-virtualization-in-standard-wpf-listview WPF ListBox with a list of virtualization and scrolling in the ListBox http://www.zagstudio.com/blog/497#.UQKxpScqb6U

+4
source

Once the image is uploaded, resize it to a more manageable size, and then release the unused large image. It will take a long time, but it will take less memory. To reduce boot time, see dutzu's answer and use lazy boot and virtualization.

0
source

Use a virtualized glass panel. Look at the link for an example of how to do this.

http://www.jonathanantoine.com/2011/10/07/wpf-4-5-%E2%80%93-part-11-new-features-for-the-virtualizingpanel/

0
source

All Articles