简体   繁体   中英

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. I use handle to capture image from uEye camera. In windows form is it

displayHandle = PictureBox.Handle

But when I use handle in WPF then I not received video from camera. In WPF i use this handle

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.

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. You can create handle before use handle not after initialize component.

Straming IDS camera to WPF component.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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