上设置网络摄像头

上设置网络摄像头

本文介绍了如何在图像控制上设置网络摄像头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在wpf应用程序的图像控件上设置网络摄像头。

我的代码是

I want to set Webcam on image control in wpf application.
My code is

public void Attach(System.Windows.Controls.Image control)
       {
               //deviceHandle = Class1.Avicap32.capCreateCaptureWindow("", Class1.Constants.WS_VISIBLE | Class1.Constants.WS_CHILD, 0, 0, control.Width, control.Height, control.Handle, 0);//Here it works but in window form application
                 deviceHandle = Class1.Avicap32.capCreateCaptureWindow(string.Empty, Class1.Constants.WS_VISIBLE | Class1.Constants.WS_CHILD, 110, 224,0,0, new WindowInteropHelper(this).Handle, 0);//it works on my window but not at image control
               if (Class1.User32.SendMessage(deviceHandle, Class1.Constants.WM_CAP_DRIVER_CONNECT, (IntPtr)0, (IntPtr)0).ToInt32() > 0)
               {
                   Class1.User32.SendMessage(deviceHandle, Class1.Constants.WM_CAP_SET_SCALE, (IntPtr)(-1), (IntPtr)0);
                   Class1.User32.SendMessage(deviceHandle, Class1.Constants.WM_CAP_SET_PREVIEWRATE, (IntPtr)0x42, (IntPtr)0);
                   Class1.User32.SendMessage(deviceHandle, Class1.Constants.WM_CAP_SET_PREVIEW, (IntPtr)(-1), (IntPtr)0);
                   Class1.User32.SetWindowPos(deviceHandle, new IntPtr(0), 0, 0, 206,187, 2);

               }
               else
               {
                   MessageBox.Show("Webcam not found ");
                   Class1.User32.DestroyWindow(deviceHandle);
               }
       }

推荐答案

xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"



添加一个window.form.picturebox


add a window.form.picturebox

<windowsformshost>
                                <wf:picturebox x:name="LiveImage" xmlns:x="#unknown" xmlns:wf="#unknown" />
                            </windowsformshost>



现在调用attach方法


and now call attach method

public void Attach(System.Windows.Controls.Image control)
        {
                deviceHandle = Class1.Avicap32.capCreateCaptureWindow("", Class1.Constants.WS_VISIBLE | Class1.Constants.WS_CHILD, 0, 0, control.Width, control.Height, control.Handle, 0);
                if (Class1.User32.SendMessage(deviceHandle, Class1.Constants.WM_CAP_DRIVER_CONNECT, (IntPtr)0, (IntPtr)0).ToInt32() > 0)
                {
                    Class1.User32.SendMessage(deviceHandle, Class1.Constants.WM_CAP_SET_SCALE, (IntPtr)(-1), (IntPtr)0);
                    Class1.User32.SendMessage(deviceHandle, Class1.Constants.WM_CAP_SET_PREVIEWRATE, (IntPtr)0x42, (IntPtr)0);
                    Class1.User32.SendMessage(deviceHandle, Class1.Constants.WM_CAP_SET_PREVIEW, (IntPtr)(-1), (IntPtr)0);
                    Class1.User32.SetWindowPos(deviceHandle, new IntPtr(0), 0, 0, 206,187, 2);
                  
                }
                else
                {
                    MessageBox.Show("Webcam not found ");
                    Class1.User32.DestroyWindow(deviceHandle);
                }   
        }


这篇关于如何在图像控制上设置网络摄像头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 08:34