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#
I got solution
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();
}
You can use the BitmapSource.CopyPixels method to copy the raw data out to a byte array. The stride parameter is the number of bytes in each image row. A 100-pixels wide RGBA image will have a stride of 100*4=400 bytes.
Check this SO discussion for the stride parameter and how it behaves for different image types