我的项目资产文件夹中有很多图像,我需要在应用程序启动时将它们加载到内存中。减少 CPU 负载和时间的最佳方法是什么。
我正在这样做:
for (int i = 0; i < 10; i++)
{
var smallBitmapImage = new BitmapImage
{
UriSource = new Uri(string.Format("ms-appx:/Assets/Themes/{0}/{1}-small-digit.png", themeName, i), UriKind.Absolute)
};
theme.SmallDigits.Add(new ThemeDigit<BitmapImage> { Value = i, BitmapImage = smallBitmapImage, Image = string.Format("ms-appx:/Assets/Themes/{0}/{1}-small-digit.png", themeName, i) });
}
然后我将此 BitmapImage 绑定到图像控件。
但我不确定设置 UriSource 是否真的将图像加载到内存中。
我还看到了 BitmapImage 的 SetSourceAsync 属性。但我不确定如何在我的上下文中使用它。任何人都可以帮助我使用 SetSourceAsync 属性或加载图像的最佳方式....
谢谢