Click here to Skip to main content
11,812,712 members (72,932 online)
Click here to Skip to main content

Rendering Color/Depth Stream using Intel Perceptual Computing in WPF

, 7 Aug 2014 CPOL 5.6K 3
Rate this:
Please Sign up or sign in to vote.
Rendering PXCMImage to Image control in WPF


When I started using the Intel perceptual computing SDK for C# I could not find any examples on  rendering the Color/Depth streams in WPF. The examples provided with the SDK are implemented in Winforms. The problem was the image obtained from Color/Depth stream is of type PXCMImage . So we could not directly render it to the Image control. After playing with the SDK and referring examples in web I was able to render the Color/Depth stream . Here is what I have done.

Using the code

We have to extract the Bitmap out of the PXCMImage type image.This can be done by two methods.

<code>PXCMImage pxcRGBImage = base.QueryImage(PXCMImage.ImageType.IMAGE_TYPE_COLOR);
PXCMImage pxcDepthImage = base.QueryImage(PXCMImage.ImageType.IMAGE_TYPE_DEPTH);

//Convert PXCMI image to bitmap
Bitmap rgbBitmap;
Bitmap depthBitmap;

// Method 1:

pxcRGBImage.QueryBitmap(session, out rgbBitmap);
pxcDepthImage.QueryBitmap(session, out depthBitmap);

But the QueryBitmap is deprecated so it is better to use method 2.

// Method 2:

PXCMImage.ImageData depthImageData;
PXCMImage.ImageData colorImageData;
pxcDepthImage.AcquireAccess(PXCMImage.Access.ACCESS_READ_WRITE, out depthImageData);
pxcRGBImage.AcquireAccess(PXCMImage.Access.ACCESS_READ_WRITE, out colorImageData);

depthBitmap = depthImageData.ToBitmap(,;
rgbBitmap = colorImageData.ToBitmap(,;

pxcRGBImage.ReleaseAccess(ref colorImageData);
pxcDepthImage.ReleaseAccess(ref depthImageData);

Points of Interest

But even after obtaining the Bitmap of Color/Depth stream we can not directly render it to the Image control. We have to convert Bitmap to BitmapImage.

In this blog it is neatly explained how to bind a Bitmap to Image control in WPF. Or you can convert the Bitmap to BitmapImage using this function (Reference:

public BitmapImage ToBitmapImage(Bitmap bitmap)
  BitmapImage bitmapImage = null;
  using (MemoryStream memory = new MemoryStream())
    bitmap.Save(memory, ImageFormat.Png);
    memory.Position = 0;
    bitmapImage = new BitmapImage();
    bitmapImage.StreamSource = memory;
    bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
  return bitmapImage;



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

India India
No Biography provided

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.151002.1 | Last Updated 8 Aug 2014
Article Copyright 2014 by naren1991
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid