4

I am integrating a webcam in a WPF application. I can see the camera feed in the main window, as I pass its HANDLE on to the DirectShow functions. But this is not what I want.

The main form has a Image control, where I'd like to see the output. However, in order to do this, I need the control's Handle.

Any hint on how to do this?

Thanks in advance, Gianluca.

Anthares
  • 1,023
  • 1
  • 13
  • 30

2 Answers2

6

An Image Control in WPF, unlike Windows Forms, doesn't actually have an HWND.

WPF works differently than Windows Forms - each control is not a wrapper around a native "window" with a handle, but rather composed together using Direct3D at runtime by the layout system.

If you need to actually host output from a Webcam inside of a WPF window, you should look at using HwndHost (or a subclass). The simplest way is often to just host a Windows Forms control inside of a WindowsFormsHost, though managing an HWND yourself via HwndHost is more efficient.

Reed Copsey
  • 522,342
  • 70
  • 1,092
  • 1,340
  • thank you! I am now trying to use the WindowsFormsHost but apparently nothing is displayed. I'm working on it and I'll let you know! Thank you again! – Anthares Sep 07 '11 at 15:43
  • 2
    @Gianluca: You'll need to put a control inside the WindowsFormsHost - I recommend putting a Windows.Forms.Panel there - then use the panel's Handle as your HWND. – Reed Copsey Sep 07 '11 at 15:46
0

Using an WindowsFormsHost and a picture box inside is a good solution that I used for a similar problem where I needed a handle to display a video stream. But be careful, in order to work, the Window that is hosting the WindowsFormsHost control must have AllowsTransparency="false"!

Remus
  • 11
  • 3