简体   繁体   English

C#WPF uEye相机捕获视频

[英]C# WPF uEye Camera capture video

I have program to capture video from camera. 我有程序可以从相机捕获视频。 Application is in windows form and I want use this code to WPF application but it is not working. 应用程序为Windows形式,我想将此代码用于WPF应用程序,但无法正常工作。 I use handle to capture image from uEye camera. 我使用手柄从uEye相机捕获图像。 In windows form is it 在Windows形式是

displayHandle = PictureBox.Handle

But when I use handle in WPF then I not received video from camera. 但是,当我在WPF中使用手柄时,我没有收到来自摄像机的视频。 In WPF i use this handle 在WPF中,我使用此句柄

HwndSource hwndSource = HwndSource.FromVisual(pbMainImage) as HwndSource;
displayHandle = hwndSource.Handle;

But still not working it 但仍然无法正常工作

Both handle I used after 我用过的两个手柄

InitializeComponent();

private void onFrameEvent(object sender, EventArgs e){
  uEye.Camera Camera = sender as uEye.Camera;

  Int32 s32MemID;
  Camera.Memory.GetActive(out s32MemID);
  Camera.Display.Render(s32MemID, displayHandle, uEye.Defines.DisplayRenderMode.FitToWindow);
}

displayHandle si handle from component pictureImage. displayHandle来自组件pictureImage的si句柄。

Thanks for help. 感谢帮助。

 HwndSource hwndSource = HwndSource.FromVisual(pbMainImage) as HwndSource;
displayHandle = hwndSource.Handle;

Do not use after 之后不要使用

InitializeComponent();

because hwndSource is null then Camera not recognize handle. 因为hwndSource为null,则Camera无法识别句柄。 You can create handle before use handle not after initialize component. 您可以在使用句柄之前而不是在初始化组件之后创建句柄。

Straming IDS camera to WPF component. 将IDS摄像机绑定到WPF组件。

private void onFrameEvent(object sender, EventArgs e)
{
      uEye.Camera Camera = sender as uEye.Camera;

      Int32 s32MemID;
      Camera.Memory.GetActive(out s32MemID);
      if (frameCamera != null)
            frameCamera.Dispose();
      frameCamera = null;
      Camera.Memory.ToBitmap(s32MemID, out frameCamera);

      Dispatcher.Invoke(new Action(() =>
      {
            pbMainImage.Source = loadBitmap(frameCamera);
      }));
}

loadBitmap(frameCamera) - Convert Bitmap to BitmapSource loadBitmap(frameCamera)-将位图转换为BitmapSource

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM