private static byte[] SendColorData(ColorFrameData data, FrameDescription fd) { if (data == null) { return(null); } var dpiX = 96.0; var dpiY = 96.0; var pixelFormat = PixelFormats.Bgra32; var bytesPerPixel = (pixelFormat.BitsPerPixel) / 8; var stride = bytesPerPixel * fd.Width; var bitmap = BitmapSource.Create(fd.Width, fd.Height, dpiX, dpiY, pixelFormat, null, data.Data, (int)stride); var encoder = new JpegBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(bitmap)); using (var ms = new MemoryStream()) using (var br = new BinaryReader(ms)) { encoder.Save(ms); ms.Flush(); ms.Position = 0; encodedBytes = br.ReadBytes((int)ms.Length); } return(encodedBytes); }
private static byte[] SendColorData(ColorFrameData data, FrameDescription fd) { if (data == null) return null; var dpiX = 96.0; var dpiY = 96.0; var pixelFormat = PixelFormats.Bgra32; var bytesPerPixel = (pixelFormat.BitsPerPixel) / 8; var stride = bytesPerPixel * fd.Width; var bitmap = BitmapSource.Create(fd.Width, fd.Height, dpiX, dpiY, pixelFormat, null, data.Data, (int)stride); var encoder = new JpegBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(bitmap)); using (var ms = new MemoryStream()) using (var br = new BinaryReader(ms)) { encoder.Save(ms); ms.Flush(); ms.Position = 0; encodedBytes = br.ReadBytes((int)ms.Length); } return encodedBytes; }