I am using the Kinect SDK and trying to add a color frame. I am using the code:
byte[] pixels = new byte[sensor.ColorStream.FramePixelDataLength];
WriteableBitmap image = new WriteableBitmap(sensor.ColorStream.FrameWidth, sensor.ColorStream.FrameHeight, 96, 96,
PixelFormats.Bgra32, null);
video.Source = image;
colorFrame.CopyPixelDataTo(pixels);
image.WritePixels(new Int32Rect(0, 0, image.PixelWidth, image.PixelHeight), pixels, image.PixelWidth * sizeof(int), 0);
But the image isn’t displaying. I know that I can connect to the Kinect because I can change the elevation angle. What am I doing wrong? Thanks in advance. Note: I am trying to avoid using Coding4Fun
Noooo, you were so close. I’m assuming
videois a WPF image.You shouldn’t be creating a new BitmapSource on every frame, it’s a lot better to create the single WriteableBitmap in the beginning and just refresh it on each frame.
Also, the reason you couldn’t see the image before wasn’t actually because it wasn’t being refreshed. It absolutely was, but it was invisible. You set the WriteableBitmap format to Bgra32, where
ais alpha. The Kinect sends data in the Bgr32 format; no alpha channel is set. So when you create a Bgra32 bitmap, it sees that the Kinect left the alpha channel set to 0, and therefore the image is shown as entirely transparent.