任意の値を含むバイト配列を作成していて、それを BitmapImage に変換したいと考えています。
bi = new BitmapImage();
using (MemoryStream stream = new MemoryStream(data))
{
try
{
bi.BeginInit();
bi.CacheOption = BitmapCacheOption.OnLoad;
bi.StreamSource = stream;
bi.DecodePixelWidth = width;
bi.EndInit();
}
catch (Exception ex)
{
return null;
}
}
このコードでは、常に NotSupportedException が発生します。任意のバイト配列から BitmapSource を作成するにはどうすればよいですか?