【发布时间】:2010-09-29 08:04:11
【问题描述】:
我的 WPF 应用程序具有多个画布和大量按钮。用户可以加载图片来改变按钮背景。
这是我在 BitmapImage 对象中加载图像的代码
bmp = new BitmapImage();
bmp.BeginInit();
bmp.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
bmp.CacheOption = BitmapCacheOption.OnLoad;
bmp.UriSource = new Uri(relativeUri, UriKind.Relative);
bmp.EndInit();
并且在 EndInit() 应用程序的内存增长非常快。
让思考变得更好(但并不能真正解决问题)的一件事是添加
bmp.DecodePixelWidth = 1024;
1024 - 我的最大画布尺寸。但我应该只对宽度大于 1024 的图像执行此操作 - 那么如何在 EndInit() 之前获得宽度?
【问题讨论】:
标签: wpf memory bitmapimage