我正在创建一个包含任意值的字节数组,并希望将其转换为BitmapImage。
这段代码经常会出现NotSupportedException异常。我该如何从任意字节数组中创建BitmapSource?
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?