void MainWindow_ColorFrameReceived(object sender, ColorFrameEventArgs e)
{
bool process = false;
process |= server.kinects[e.kinectID].version == KinectVersion.KinectV1;
if (!process && server.kinects[e.kinectID].version == KinectVersion.KinectV2)
{
process |= ((KinectV2Wrapper.Settings)server.serverMasterOptions.kinectOptionsList[e.kinectID]).useIRPreview == e.isIR;
}
if (process)
{
if (colorSource == null)
{
colorSource = new WriteableBitmap(e.width, e.height, 96.0, 96.0, e.pixelFormat, null);
ColorImage.Source = colorSource;
}
else if (colorSource.PixelWidth != e.width || colorSource.PixelHeight != e.height || colorSource.Format != e.pixelFormat)
{
colorSource = null;
colorSource = new WriteableBitmap(e.width, e.height, 96.0, 96.0, e.pixelFormat, null);
ColorImage.Source = colorSource;
}
colorSource.WritePixels(new Int32Rect(0, 0, e.width, e.height), e.image, e.width * e.bytesPerPixel, 0);
//Calculate and display the frame rate
double tempFPS = CalculateFrameRate(e.timeStamp, ref lastColorTime, ref colorTimeIntervals);
ColorFPSTextBlock.Text = tempFPS.ToString("F1");
}
}