2017-09-29 17 views
1

Je veux afficher la sortie WEBCAM sur un contrôle IMAGE dans WPF pendant que l'utilisateur se positionne pour prendre un passeport. J'utilise la bibliothèque DirectShow et je peux capturer l'image et le placer dans le contrôle Image, mais le contrôle Image reste vide jusqu'à ce que je capture l'image. S'il vous plaît comment puis-je m'assurer que le contrôle de l'image montre la sortie de la webcam avant que l'utilisateur ne capture son image? Mercicomment héberger la sortie d'une Webcam à l'intérieur d'un WPF ImageControl en utilisant directShow

c'est la fonction que je ressens contrôle ce que je veux réaliser

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); 
    } 

je l'ai commenté la ligne que je pense que mon problème vient. Merci pour votre aide

Répondre

0

J'ai finalement compris comment le faire. je devais utiliser un windowsformhost pour accueillir une boîte de forme de fenêtres d'image dans la grille de mon code XAML comme celui-ci

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

     </WindowsFormsHost> 

alors j'ajouté la zone d'image dans le constructeur de cette page XAML comme celui-ci

// 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); 

alors j'ai modifié la fonction dans ma question à ce

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); 
    } 

J'espère que cela aide quelqu'un. Notez que la fenêtre qui contient la page xaml que vous avez placée dans votre windowsformhost ne doit pas avoir la transparence définie sur true, sinon, elle n'apparaîtra pas.

0

Vous pouvez créer graphique DirectShow comme:

Webcam ---> SampleGrabber -> Null Renderer

Il vous donnera un flux en direct, en utilisant que vous pouvez capturer l'image.

Peut-être que cela vous aidera.

+0

mais j'ai lu que l'échantillonneur d'échantillons est déprécié –

+0

Mais pas supprimé. Vous pouvez toujours l'utiliser. – iamyz

+0

ok, laissez-moi essayer –