可能這聽起來很愚蠢,但是,哪一個是加載圖像最有效的方式?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