BitmapImage与ImageBrush的性能

时间:2014-10-09 07:57:11

标签: c# wpf image performance xaml

我试过四处寻找,但我找不到这个问题的答案:使用ImageBrush填充矩形而不是创建BitmapImage并设置其源属性是否有性能改进?

我必须渲染大量图像(我们试图推动超过5000),现在我正在以这种方式创建它们:

<Image x:Name="img" RenderOptions.BitmapScalingMode="LowQuality"
    Source="{Binding Path, Converter={StaticResource StringToImageConverter}, ConverterParameter={StaticResource string}}" >
</ext:IdImage>

并在转换器中:

System.Windows.Media.Imaging.BitmapImage image = new System.Windows.Media.Imaging.BitmapImage();
image.BeginInit();
image.UriSource = new Uri(value as String);
image.DecodePixelWidth = int.Parse((String)parameter);
image.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
image.EndInit();
return image;

注意:我必须使用转换器来设置DecodePixelWidth属性。

使用ImageBrush我可以根据我读到的内容冻结画笔,提高性能,所以我想知道是否应该改变构建图像的方式。

P.S。图像不是静态的,而是被翻译出来的。

1 个答案:

答案 0 :(得分:0)

我认为问题不在代码中,而是在体系结构WPF中。

如果您的问题是性能问题,根据我的个人经验,开发XAML是必要的,因为PC最好配备专用的视频卡。然而,很多时候即使在非常老的电脑上使用Windows XP来瘦身程序我也安装了更新直接X库

http://support.microsoft.com/kb/179113/en

XAML基于directX

试一试,让我知道