245px * 135px以下のサイズのウィンドウに多くの画像を表示したい、画像は異なるサイズにすることができるので、少なくとも幅> 245または高さ> 135の画像のサイズを変更したい.私はそれをしようとします:
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri(filepath);
bi.CacheOption = BitmapCacheOption.OnLoad;
bi.EndInit();
if (bi.Width > bi.Height)
{
bi.DecodePixelHeight = Convert.ToInt32(bi.Height * (245 / bi.Width));
bi.DecodePixelWidth = 245;
}
else
{
bi.DecodePixelWidth = Convert.ToInt32(bi.Width * (135 / bi.Height));
bi.DecodePixelHeight = 135;
}
しかし、EndIint() の前に行う必要があるため、DecodePixelXXX は 0 です。しかし、私は幅/高さをまだ知らないので、EndInit の前にそれを行うことはできません。最大のパフォーマンスで画像全体を BitmapImage にロードせずにそれを行う方法は?