Possible Duplicate:
WPF Image to byte[]
Relative to this I have a BitmapSource image obtained by capturing image from webcam.How can i convert it to byte[] in C#
Possible Duplicate:
WPF Image to byte[]
Relative to this I have a BitmapSource image obtained by capturing image from webcam.How can i convert it to byte[] in C#
我得到了解决方案
JpegBitmapEncoder encoder = new JpegBitmapEncoder();
//encoder.Frames.Add(BitmapFrame.Create(bitmapSource));
encoder.QualityLevel = 100;
// byte[] bit = new byte[0];
using (MemoryStream stream = new MemoryStream())
{
encoder.Frames.Add(BitmapFrame.Create(bitmapSource));
encoder.Save(stream);
byte[] bit = stream.ToArray();
stream.Close();
}
您可以使用BitmapSource.CopyPixels方法将原始数据复制到字节数组中。stride 参数是每个图像行中的字节数。一个 100 像素宽的 RGBA 图像的步长为 100*4=400 字节。
检查此SO 讨论以了解 stride 参数及其对不同图像类型的行为方式