I am doing Kinect programming and when I enable the color stream, I defined to use Bayer 30 frames per second format (ColorImageFormat.RawBayerResolution640x480Fps30).
When rendering the image, I use the following code:
PixelFormat format = PixelFormats.Bgr32;
// Bitmap source to write to.
WriteableBitmap src = new WriteableBitmap((int)_kinectSensor.ColorStream.FrameWidth, (int)_kinectSensor.ColorStream.FrameHeight, 96, 96, format, null);
// Stride for image.
var stride = (int)_kinectSensor.ColorStream.FrameWidth * format.BitsPerPixel / 8;
// Write pixels to bitmap source.
src.WritePixels(new Int32Rect(0, 0, (int)imgPic.Width, (int)imgPic.Height), rawBayerPixels, stride, 0);
// Set XAML image source = Bitmap source.
imgPic.Source = src;
How do I workout the PixelFormat without hardcoding as above, based on the selected ColorImageFormat?
Thanks in advance!
Just incase anyone's interested, here's how I ended up doing it: