DepthImageFrame.CopyDepthImagePixelDataTo Method (IntPtr, Int32)

Kinect for Windows 1.5, 1.6, 1.7, 1.8

Copies the per-pixel depth data to a pre-allocated byte array using the pixel data length.

public void CopyDepthImagePixelDataTo (
         IntPtr pixelData,
         int pixelDataLength


Type: IntPtr
Address of a byte array to receive the pixel data. The array size must be equal to sizeof(DepthImagePixel) times the PixelDataLength property.
Type: Int32
The number of pixels in the frame (as obtained from the PixelDataLength property).

Each pixel of depth data is stored in a DepthImagePixel; therefore the array must have sufficient room for all of the DepthImagePixel values in the frame. Here's an example:

  // For depth data
  //frame = DepthImageFrame
  IntPtr pixelData = Marshal.AllocHGlobal(sizeof(DepthImagePixel) * frame.PixelDataLength);
    frame.CopyDepthImagePixelDataTo(pixelData, frame.PixelDataLength);
    // use the data that has been copied to pixelData
    if (pixelData != IntPtr.Zero) Marshal.FreeHGlobal(pixelData);

Namespace: Microsoft.Kinect
Assembly: Microsoft.Kinect (in microsoft.kinect.dll)