使用方法如下:
void sensor_ColorFrameReady(AllFramesReadyEventArgs e)
{
using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
{
if (colorFrame == null)
{
return;
}
//set image
ColorImage.Source = colorFrame.ToBitmapSource();
if (_saveColorFrame)
{
//save image
colorFrame.ToBitmapSource().Save(DateTime.Now.ToString("yyyyMMddHHmmss") + "_color.jpg", ImageFormat.Jpeg);
}
}
}
void sensor_DepthFrameReady(AllFramesReadyEventArgs e)
{
using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
{
if (depthFrame == null)
{
return;
}
//turn raw data into an array of distances;
var depthArray = depthFrame.ToDepthArray();
MidPointDistanceViaGetDistanceText.Text = depthFrame.GetDistance(depthFrame.Width/2, depthFrame.Height/2).ToString();
//image
DepthImageWithMinDistance.Source = depthArray.ToBitmapSource(depthFrame.Width, depthFrame.Height,
_minDistance, Colors.Red);
//image
DepthImage.Source = depthFrame.ToBitmapSource();
if (_saveDepthFrame)
{
_saveDepthFrame = false;
depthFrame.ToBitmapSource().Save(DateTime.Now.ToString("yyyyMMddHHmmss") + "_depth.jpg", ImageFormat.Jpeg);
}
}
}