I want to display a GIF by using a library WPF Animated GIF. But when the property PictureSource
is set, the process memory rises from 208MB to 1GB. Why?
XAML
<Image Name="content" MaxHeight="240" MaxWidth="340"
RenderOptions.BitmapScalingMode="LowQuality"
Width="340" Height="240"
MinWidth="340" MinHeight="240"
gif:ImageBehavior.AutoStart="True"
gif:ImageBehavior.AnimatedSource="{Binding Path=PictureSource}">
<Image.Stretch>
<MultiBinding Converter="{StaticResource ImageStretchConverter}">
<Binding Path="PictureSource" />
<Binding ElementName="content" Path="Source.Width" />
<Binding ElementName="content" Path="Source.Height" />
</MultiBinding>
</Image.Stretch>
<Image.BitmapEffect>
<BlurBitmapEffect Radius="0" />
</Image.BitmapEffect>
<Image.CacheMode>
<BitmapCache EnableClearType="True"
RenderAtScale="0.2"
SnapsToDevicePixels="True"/>
</Image.CacheMode>
<!--<Image.Source>
<BitmapImage StreamSource="{Binding Path=PictureSource}" UriSource="{Binding Path=PictureSource}"
DecodePixelWidth="340" DecodePixelHeight="240"/>
</Image.Source>-->
</Image>
ImageStretchConverter
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) {
string path = values[0] as string;
if (string.IsNullOrEmpty(path) || values[1] == DependencyProperty.UnsetValue || values[2] == DependencyProperty.UnsetValue) {
return Stretch.None;
}
if (Path.GetExtension(path).ToLower() == ".gif") {
double width = (double)values[1];
double height = (double)values[2];
if (width > Configuration.MaxThumbnailResolution || height > Configuration.MaxThumbnailResolution) {
return Stretch.UniformToFill;
}
}
return Stretch.None;
}
The size of the original GIF image is quite high. This may cause the problem. How can I set the DecodePixelWidth
and DecodePixelHeight
of the AnimatedSource
?