public void RepaintColorFrame(byte[] bgr, int width, int height) { if (TextDepth != null) { var avg = DepthWatch.Average(); if (!String.IsNullOrWhiteSpace(avg)) { TextDepth.Text = "Depth: " + avg; } } if (TextColor != null) { var avg = ColorWatch.Average(); if (!String.IsNullOrWhiteSpace(avg)) { TextColor.Text = "Color: " + avg; } } if (TextBody != null) { var avg = BodyWatch.Average(); if (!String.IsNullOrWhiteSpace(avg)) { TextBody.Text = "Body: " + avg; } } }
private async Task RepaintAsync(TimeSpan dueTime, TimeSpan interval, CancellationToken token) { // Initial wait time before we begin the periodic loop. if (dueTime > TimeSpan.Zero) { await Task.Delay(dueTime, token); } // Repeat this loop until cancelled. while (!token.IsCancellationRequested) { // Timestamp data RepaintWatch.Again(); // Do Job try { // Init once InitRepaint(); // Copy frame ColorFrame color = (ColorFrame)Descriptor.Find(typeof(ColorFrame)); if (color != null) { Buffer.BlockCopy(color.Pixels, 0, drawer, 0, color.Pixels.Length); // Buffer.BlockCopy(Infrared, 0, drawer, 0, Infrared.Length); // Ask repaint to addons AddOnManager.GetInstance().RepaintColorFrame(Name, drawer, color.Width, color.Height); } // Resize scale.Bytes = drawer; var resize = scale.Resize(w, h, Emgu.CV.CvEnum.Inter.Cubic); bitmap.WritePixels(rect, resize.Bytes, stride, 0); // Ticks this.Repaint.Text = "Repaint: " + RepaintWatch.Average(); } catch (Exception ex) { Error(ex); } RepaintWatch.Stop(); // Wait to repeat again. try { if (interval > TimeSpan.Zero) { await Task.Delay(interval, token); } } catch (ThreadInterruptedException) { break; } } }