私は問題があります。配列に変換BitmapImage
して元に戻したい。byte[]
私はこれらのメソッドを書きました:
public static byte[] ToByteArray(this BitmapImage bitmapImage)
{
byte[] bytes;
using (MemoryStream ms = new MemoryStream())
{
bitmapImage.BeginInit();
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.StreamSource.CopyTo(ms);
bitmapImage.EndInit();
bytes = ms.ToArray();
}
return bytes;
}
public static BitmapImage ToBitmapImage(this byte[] bytes, int width, int height)
{
BitmapImage bitmapImage = new BitmapImage();
using (MemoryStream ms = new MemoryStream(bytes))
{
ms.Position = 0;
bitmapImage.BeginInit();
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.StreamSource = ms;
bitmapImage.EndInit(); // HERE'S AN EXCEPTION!!!
}
return bitmapImage;
}
最初のものは正常に動作しますが、からに変換しようとするとbyte[]
...BitmapImage
なぜNotSupportedException
ですか? 2番目の方法のコードを修正するには?