[英]Create a WriteableBitmap from a byte array wpf
从示例中,我已经能够创建BitmapImage字节数组
public byte[] BufferFromImage(BitmapImage myImageFile)
{
WriteableBitmap btmMap = new WriteableBitmap(BitmapFactory.ConvertToPbgra32Format(myImageFile));
return btmMap.ToByteArray();
}
现在,我正在寻求扭转这种情况,但是到目前为止,没有成功,我已经检查了https://writeablebitmapex.codeplex.com ,其中指出它可以从字节数组创建WriteableBitmap,但是我还没有找到任何示例。
public WriteableBitmap ByteArrayToImage(Byte[] BArray)
{
var width = 100;
var height = 100;
var dpiX = 96d;
var dpiY = 96d;
var pixelFormat = PixelFormats.Pbgra32;
var bytesPerPixel = (pixelFormat.BitsPerPixel + 7) / 8;
var stride = bytesPerPixel * width;
var bitmap = BitmapImage.Create(width, height, dpiX, dpiY, pixelFormat, null, BArray, stride);
WriteableBitmap wbtmMap = new WriteableBitmap(BitmapFactory.ConvertToPbgra32Format(bitmap));
return wbtmMap;
}
这返回一个错误
用户代码未处理System.ArgumentException消息=缓冲区大小不足。
我希望有人能指出正确的方向
尝试增加缓冲区的大小...缓冲区大小的计算应像步幅*高度一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.