无论如何,将WriteableBitmap转换为字节数组?如果有一种方法可以将writeablebitmap分配给System.Windows.Controls.Image源,也可以将其分配给System.Windows.Controls.Image源。我试过了,但是在FromHBitmap上遇到了一般的GDI异常。
System.Drawing.Image img = System.Drawing.Image.FromHbitmap(wb.BackBuffer);
MemoryStream ms = new MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
myarray = ms.ToArray();
您的代码将图像数据编码为PNG格式,但FromHBitmap
需要原始的未编码位图数据。
试试这个:
var width = bitmapSource.PixelWidth;
var height = bitmapSource.PixelHeight;
var stride = width * ((bitmapSource.Format.BitsPerPixel + 7) / 8);
var bitmapData = new byte[height * stride];
bitmapSource.CopyPixels(bitmapData, stride, 0);
...bitmapSource
您WriteableBitmap
(或其他任何人BitmapSource
)在哪里?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句