WPF动画GIF使用太多的内存来显示大的GIF图像 [英] WPF Animated GIF Use Too Much Memory for Displaying Large GIF Image
问题描述
我想通过使用库 WPF动画GIF 显示GIF.但是,设置属性PictureSource
时,进程内存将从 208MB 增加到 1GB .为什么?
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?
<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;
}
原始GIF图像的尺寸很大.这可能会导致问题.如何设置AnimatedSource
的DecodePixelWidth
和DecodePixelHeight
?
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
?
推荐答案
您是否已阅读此问题的文章? https ://www.thomaslevesque.com/2015/01/17/a-new-library-to-display-animated-gifs-in-xaml-apps/
Have you read this article on the problem? https://www.thomaslevesque.com/2015/01/17/a-new-library-to-display-animated-gifs-in-xaml-apps/
问题很可能是由开发人员在创建库时犯的错误引起的. 您可以在文章中阅读所有相关内容,但需要简短说明.
The problem is most likely caused by a mistake the developer made when creating the library. You can read all about it in the article, but for a short explanation.
所有帧都在内存中预先渲染,对于大的gif来说,这是一个大问题.遗憾的是,使用相同的库而不重新编程时,确实没有一个简单的解决方案.
All the frames are pre-rendered in memory, for large gifs this is a big problem. Sadly enough there really isn't a easy fix for that when using the same library without re-programming it.
我建议尝试使用 XamlAnimatedGif .
https://github.com/thomaslevesque/XamlAnimatedGif
(由 Same Developer 制作)
这篇关于WPF动画GIF使用太多的内存来显示大的GIF图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!