Multiple screens for WPF controls

Place Image control on form, call it imgScreen. Add OnVideoFrameBuffer event for SDK control.

private WriteableBitmap bitmap;

public delegate void NewFrameDelegate(VideoFrameBufferEventArgs e);

public void NewFrameDelegateMethod(VideoFrameBufferEventArgs e)
{
    if (bitmap != null && (bitmap.PixelWidth != e.Width || bitmap.PixelHeight != e.Height))
    {
        bitmap = null;
        imgScreen.BeginInit();
        imgScreen.Source = null;
        imgScreen.EndInit();
    }

    if (bitmap == null)
    {
        bitmap = new WriteableBitmap(e.Width, e.Height, 72, 72, PixelFormats.Bgr24, null);
        imgScreen.Source = bitmap;
    }

    imgScreen.BeginInit();

    bitmap.WritePixels(new Int32Rect(0, 0, e.Width, e.Height), e.Buffer, e.Width * 3, 0, 0);

    imgScreen.EndInit();
}

private void VideoCapture1_OnVideoFrameBuffer(object sender, VideoFrameBufferEventArgs e)
{
    Dispatcher.BeginInvoke(new NewFrameDelegate(NewFrameDelegateMethod), e);
}

VisioForge © 2006-2019

  • GitHub-Mark-64px
  • Twitter Социальные Иконка
  • VisioForge Facebook page
  • YouTube channel