我如何获取列表网络摄像头设备使用C#中的API连接到系统? [英] How i can get list webcam devices connect to system with API in c#?

查看:538
本文介绍了我如何获取列表网络摄像头设备使用C#中的API连接到系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.
我使用以下代码获取网络摄像头设备列表,但返回的名称不等于设备名称.
我想使用设备索引连接到网络摄像头设备.
帮帮我.谢谢.

Hello.
I use following code to get list of webcam devices but return Name not equal to device name.
I want to connect to webcam device using index of device.
help me.thanks.

      ArrayList ListOfDevices = new ArrayList();
      string Name = String.Empty.PadRight(50);
      string Version = String.Empty.PadRight(100);
      bool EndOfDeviceList = false;
      short index = 0;
      int DeviceID = 0;
     [DllImport("avicap32.dll")]
      protected static extern bool capGetDriverDescriptionA(short wDriverIndex,
          [MarshalAs(UnmanagedType.VBByRefStr)]ref String lpszName,
           int cbName, [MarshalAs(UnmanagedType.VBByRefStr)] ref String lpszVer, int cbVer);


do
          {
              // Get Driver name and version
              EndOfDeviceList = capGetDriverDescriptionA(index, ref Name, 100, ref Version, 100);
              // If there was a device add device name to the list
              if (EndOfDeviceList)
                  ListOfDevices.Add(Name.Trim());
                  //c1.Items.Add(Name.Trim());
              index += 1;
          }
          while (!(EndOfDeviceList == false));

          foreach (string NameCamera in ListOfDevices)
          {
              int i = 0;
              if (NameCamera == "device name")
                  DeviceID = i;
              i++;
          }
          SendMessage(mCapHwnd, WM_CAP_CONNECT, DeviceID, 0);
          SendMessage(mCapHwnd, WM_CAP_SET_PREVIEWRATE, 66, 0);   //66
          SendMessage(mCapHwnd, WM_CAP_SET_PREVIEW, 1, 0);

推荐答案

您可能需要为此进行一些COM编程. 这可以为您提供很好的参考:

参见此
You might need to do some COM programming for this.
This can be a good reference for you :

See this


这篇关于我如何获取列表网络摄像头设备使用C#中的API连接到系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆