2017-09-29 18 views
1

사용자가 자신의 입장에서 여권을 가져갈 때 WPF의 IMAGE 컨트롤에 WEBCAM 출력을 표시하려고합니다. DirectShow 라이브러리를 사용하고 있는데 이미지를 캡처하여 이미지 컨트롤에 배치 할 수 있지만 이미지를 캡처 할 때까지는 이미지 컨트롤이 비어 있습니다. 사용자가 자신의 이미지를 캡처하기 전에 이미지 컨트롤에 웹캠 출력이 표시되도록하려면 어떻게해야합니까? 감사합니다directShow를 사용하여 WPF ImageControl 내부의 웹캠에서 출력을 호스트하는 방법

이 난 내가 내 문제에서 오는 생각 라인을 댓글을 달았

private void ConfigVideoWindow(System.Windows.Controls.Image hControl) 
    { 
     HwndSource source = (HwndSource)HwndSource.FromVisual(hControl); 
     int hr; 

     IVideoWindow ivw = m_FilterGraph as IVideoWindow; 

     // Set the parent 
     hr = ivw.put_Owner(source.Handle);//i need to create an handle for the image control and pass it here. but i cannot do that 
     DsError.ThrowExceptionForHR(hr); 

     // Turn off captions, etc 
     hr = ivw.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipChildren | WindowStyle.ClipSiblings); 
     DsError.ThrowExceptionForHR(hr); 

     // Yes, make it visible 
     hr = ivw.put_Visible(OABool.True); 
     DsError.ThrowExceptionForHR(hr); 

     // Move to upper left corner 
     Rectangle rc = new Rectangle();// changed from hControl.ClientRectangle 
     hr = ivw.SetWindowPosition(0, 0, Convert.ToInt32(hControl.Height), Convert.ToInt32(hControl.Width)); 
     DsError.ThrowExceptionForHR(hr); 
    } 

를 달성하기 위해 원하는 컨트롤을 느끼는 기능입니다. 덕분에 당신의 도움

답변

0

나는 마침내 어떻게하는지 알게되었습니다. 내가이

 <WindowsFormsHost Name="ima" HorizontalAlignment="Left" Height="300" Margin="98,105,0,0" VerticalAlignment="Top" Width="350" Background="Black" > 

     </WindowsFormsHost> 

처럼 내 XAML 코드의 그리드에서 윈도우 폼 그림 상자를 호스트 할 windowsformhost을 사용했다 그럼 내가이

// Create the interop host control. 
     System.Windows.Forms.Integration.WindowsFormsHost host = 
      new System.Windows.Forms.Integration.WindowsFormsHost(); 

     // Create the PictureBox control. 
     PictureBox picBox = new PictureBox(); 
     picBox.Width = 350; 
     picBox.Height = 300; 
     // Assign the MaskedTextBox control as the host control's child. 
     ima.Child = picBox; 

     // Add the interop host control to the Grid 
     // control's collection of child controls. 
     this.grid1.Children.Add(host); 
등이 XAML 페이지의 생성자에서 그림 상자를 추가

는 내가이 사람을 도움이되기를 바랍니다이

private void ConfigVideoWindow(System.Windows.Forms.PictureBox picBox) 
    { 
     int hr; 

     IVideoWindow ivw = m_FilterGraph as IVideoWindow; 

     // Set the parent 
     hr = ivw.put_Owner(picBox.Handle); 
     DsError.ThrowExceptionForHR(hr); 

     // Turn off captions, etc 
     hr = ivw.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipChildren | WindowStyle.ClipSiblings); 
     DsError.ThrowExceptionForHR(hr); 

     // Yes, make it visible 
     hr = ivw.put_Visible(OABool.True); 
     DsError.ThrowExceptionForHR(hr); 

     // Move to upper left corner 
     Rectangle rc = picBox.ClientRectangle; 
     hr = ivw.SetWindowPosition(0, 0, rc.Right, rc.Bottom); 
     DsError.ThrowExceptionForHR(hr); 
    } 

에 내 질문에서 함수를 수정했습니다. windowsformhost에 배치 한 xaml 페이지가 들어있는 창은 투명도가 true로 설정되면 안됩니다. 그렇지 않으면 표시되지 않습니다.

0

을 위해 당신은 DirectShow를 그래프를 만들 수 있습니다와 같은 :

웹캠 ---> SampleGrabber -> 널 렌더러

그것은 당신이 이미지를 캡처 할 수있는 사용하여, 당신에게 라이브 스트림을 제공 할 것입니다.

도움이 될 수 있습니다.

+0

하지만 그 샘플 그래버는 더 이상 사용되지 않습니다. –

+0

하지만 제거되지는 않았습니다. 당신은 여전히 ​​그것을 사용할 수 있습니다. – iamyz

+0

좋습니다, 시도하겠습니다. –