gpt4 book ai didi

c# - 最小化图像的内存消耗列表框(WPF)

转载 作者:太空狗 更新时间:2023-10-29 21:45:37 28 4
gpt4 key购买 nike

我有绑定(bind)到 ObservableCollection 的列表框,并使用文件名来显示图像 enter image description here

我的 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>

问题是,它会加载整个图像,如果我有大量图片,它会消耗大量内存。如何最小化它的内存消耗?

最佳答案

关于c# - 最小化图像的内存消耗列表框(WPF),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14525859/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com