Exemple #1
0
        public void Update(ImageFrameReadyEventArgs e)
        {
            if (depthFrame32 == null)
            {
                depthFrame32 = new byte[e.ImageFrame.Image.Width * e.ImageFrame.Image.Height * 4];
            }

            ConvertDepthFrame(e.ImageFrame.Image.Bits);

            if (DepthBitmap == null)
            {
                DepthBitmap = new WriteableBitmap(e.ImageFrame.Image.Width, e.ImageFrame.Image.Height, 96, 96, PixelFormats.Bgra32, null);
            }

            DepthBitmap.Lock();

            int       stride    = DepthBitmap.PixelWidth * DepthBitmap.Format.BitsPerPixel / 8;
            Int32Rect dirtyRect = new Int32Rect(0, 0, DepthBitmap.PixelWidth, DepthBitmap.PixelHeight);

            DepthBitmap.WritePixels(dirtyRect, depthFrame32, stride, 0);

            DepthBitmap.AddDirtyRect(dirtyRect);
            DepthBitmap.Unlock();

            RaisePropertyChanged(() => DepthBitmap);
        }
Exemple #2
0
        //Draw Depth Frame
        public static void DrawDepthFrame(TDepthFrame depthFrame)
        {
            int minDepth = depthFrame.MinDepth;
            int maxDepth = depthFrame.MaxDepth;

            // Convert the depth to RGB
            int colorPixelIndex = 0;

            for (int i = 0; i < depthFrame.DepthData.Length; ++i)
            {
                short depth     = depthFrame.DepthData[i];
                byte  intensity = (byte)(depth >= minDepth && depth <= maxDepth ? depth : 0);

                ColorPixels[colorPixelIndex++] = intensity;
                ColorPixels[colorPixelIndex++] = intensity;
                ColorPixels[colorPixelIndex++] = intensity;

                ++colorPixelIndex;
            }

            DepthBitmap.WritePixels(
                new Int32Rect(0, 0, DepthBitmap.PixelWidth, DepthBitmap.PixelHeight),
                ColorPixels,
                DepthBitmap.PixelWidth * sizeof(int),
                0);
        }