我将 BitmapImage 保存到 byte[] 以保存在数据库中。我很确定数据正在被准确地保存和检索,所以这不是问题。
在我的 byte[] 到 BitmapImage 的转换中,我不断收到“System.NotSupportedException:找不到适合完成此操作的成像组件”的异常。
谁能看到我在这里的两个功能做错了什么?
private Byte[] convertBitmapImageToBytestream(BitmapImage bi)
{
int height = bi.PixelHeight;
int width = bi.PixelWidth;
int stride = width * ((bi.Format.BitsPerPixel + 7) / 8);
Byte[] bits = new Byte[height * stride];
bi.CopyPixels(bits, stride, 0);
return bits;
}
public BitmapImage convertByteToBitmapImage(Byte[] bytes)
{
MemoryStream stream = new MemoryStream(bytes);
stream.Position = 0;
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.StreamSource = stream;
bi.EndInit();
return bi;
}