可能这听起来很愚蠢,但是,哪一个是加载图像最有效的方式?WPF最有效的加载方式图片
一个
BitmapImage bmp = new BitmapImage();
using(FileStream fileStream = new FileStream(source_path, FileMode.Open))
{
bmp.BeginInit();
bmp.CacheOption = BitmapCacheOption.OnLoad;
bmp.StreamSource = fileStream;
bmp.EndInit();
if (bmp.CanFreeze)
bmp.Freeze();
images.source = bmp;
}
乙
BitmapImage bmp = new BitmapImage();
bmp.BeginInit();
bmp.CacheOption = BitmapCacheOption.OnLoad;
bmp.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
bmp.UriSource = new Uri(source_path);
bmp.EndInit();
if (bmp.CanFreeze)
bmp.Freeze();
images.Source = bmp;
我记得我从一个流中读取的地方,装载完全禁用缓存。如果这是真的,是否意味着从内存管理角度来看,从流中加载更好?
您最终需要在case A中处理'fileStream'。 – usr
你能用秒表来测量吗? – kenny
@usr是的。代码已更新。 – Reyn