C#带有DShow.Net/DirectX.Capture的网络摄像头:显示设备名称

C#带有DShow.Net/DirectX.Capture的网络摄像头:显示设备名称,c#,directx,webcam,directshow,C#,Directx,Webcam,Directshow,你好。我使用DShow.Net/DirectX.Capture控制usb网络摄像头。它找到并初始化所有连接的设备,但它显示设备名称,以拥有按钮编号(1.2.3…)。我想显示设备的全名。我的代码示例: if (filters.VideoInputDevices != null) { for (var i = 0; i < filters.VideoInputDevices.Count; i++) {

你好。我使用DShow.Net/DirectX.Capture控制usb网络摄像头。它找到并初始化所有连接的设备,但它显示设备名称,以拥有按钮编号(1.2.3…)。我想显示设备的全名。我的代码示例:

if (filters.VideoInputDevices != null)
            {
                for (var i = 0; i < filters.VideoInputDevices.Count; i++)
                {
                    var device = filters.VideoInputDevices[i];

                    var btn = new Button();

                    btn.Text = i.ToString();
                    btn.ForeColor = Color.White;
                    btn.BackColor = Color.DarkSlateBlue;
                    btn.Width = 50;

                    btn.Click += (obj, evt) =>
                    {
                        var thisButton = (Button)obj;

                        if (int.Parse(thisButton.Text) != deviceName)
                        {
                            if (capture != null)
                            {
                                capture.Dispose();
                                capture.Stop();
                                capture.PreviewWindow = null;
                            }

                            deviceName = int.Parse(thisButton.Text);
                            preview(deviceName);
                        }
                    };

                    flowLayoutPanel1.Controls.Add(btn);
                }
            }
if(filters.VideoInputDevices!=null)
{
对于(变量i=0;i
{
var thisButton=(按钮)obj;
if(int.Parse(thisButton.Text)!=deviceName)
{
如果(捕获!=null)
{
capture.Dispose();
capture.Stop();
capture.PreviewWindow=null;
}
deviceName=int.Parse(thisButton.Text);
预览(deviceName);
}
};
flowLayoutPanel1.Controls.Add(btn);
}
}
更改

btn.Text = i.ToString();

然后

请注意,询问StackOverflow问题的经验法则是:

  • 研究工作
  • 对已解决问题的最低理解

    • 你必须这样做

      'if (filters.VideoInputDevices != null)
       {
       for (var i = 0; i < filters.VideoInputDevices.Count; i++)
       {
       var device = filters.VideoInputDevices[i];
      here Device has a collection so you have to Store in an Array and then split                            
      string Decive[] = device.split('');//Split it based on some parameter 
      
      'if(filters.VideoInputDevices!=null)
      {
      对于(变量i=0;i
      //在这里换车 var btn=新按钮(); 在这里输入代码 btn.text=设备[1]。text;'


      ///我想其余的代码都是一样的

      我不熟悉您所说的库。如果您能给我指出一个文档,我可能会对您更有帮助。但您的问题在于btn.Text=i.ToString();。您需要将其写入类似
      btn.Text=device.Name;
      或其他内容。同样,文档将帮助您确定需要使用的内容。由于
      int.Parse(thisButton.Text)
      您尝试将文本解析为
      int
      。我无法使用if(thisButton.Text!=deviceName)因为我得到错误运算符“!=”不能应用于“string”和“int”类型的操作数,并更改
      deviceName=int.Parse(thisButton.Text);
      into
      deviceName=thisButton.Text;
      和deviceName to string.@Fakt7如果您遇到新的错误,请另外问一个问题,说明您正在尝试执行的操作。当然可以修复它,但正如Roman R所述,您需要进一步研究和理解您的代码。我们将为您修复这一部分,但另一部分是你的程序将中断。我看不到你在哪里设置
      deviceName
      ,我甚至不知道deviceName的类型,它是int、string、double吗?请更简洁地回答你的问题。Roman R,+1 btw。
      if (int.Parse(thisButton.Text) != deviceName)
      
      if (thisButton.Text != deviceName)
      
      'if (filters.VideoInputDevices != null)
       {
       for (var i = 0; i < filters.VideoInputDevices.Count; i++)
       {
       var device = filters.VideoInputDevices[i];
      here Device has a collection so you have to Store in an Array and then split                            
      string Decive[] = device.split('');//Split it based on some parameter