LOOK LOOK - 3 months ago 91
C# Question

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.

Answer
 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.

Comments