【问题标题】:C# webcam with DShow.Net/ DirectX.Capture: show devices names带有 DShow.Net/DirectX.Capture 的 C# 网络摄像头:显示设备名称
【发布时间】:2014-05-04 19:15:15
【问题描述】:

美好的一天。我用 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);
                }
            }

【问题讨论】:

  • 我不熟悉你所说的库。如果您能指出我的文档,我可能会为您提供更多帮助。但是你的问题在于btn.Text = i.ToString();。你需要把它写成btn.Text = device.Name; 之类的东西。同样,文档将帮助您确定需要使用什么。

标签: c# directx webcam directshow


【解决方案1】:

改变

btn.Text = i.ToString();

btn.Text = device.Name;

然后

if (int.Parse(thisButton.Text) != deviceName)

if (thisButton.Text != deviceName)

请注意,在 StackOverflow 上提问的经验法则是:

  • 研究工作
  • 对所解决问题的了解很少

【讨论】:

  • 由于int.Parse(thisButton.Text),您尝试将文本解析为int,因此出现错误。
  • 我不能使用 if (thisButton.Text != deviceName) 因为我得到错误 Operator '!=' cannot be applied to 'string' and 'int' 类型的操作数
  • 并将deviceName = int.Parse(thisButton.Text); 更改为deviceName = thisButton.Text; 并将设备名称更改为字符串。 @Fakt7 如果您遇到新错误,请提出一个单独的问题,并在其中解释您要执行的操作。
  • 当然可以修复它,但正如 Roman R. 所提到的,您需要研究更多地了解您的代码。我们将为您修复这部分,但您的程序的另一部分将中断。我看不到你在哪里设置deviceName,我什至不知道 deviceName 的类型是什么,它是 int、string 还是 double?更简洁地回答您的问题。 Roman R.,+1 顺便说一句。
【解决方案2】:

你必须这样做。

'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 

// 在此处更改 var btn = 新按钮(); 在这里输入代码 btn.text = 设备[1].text ;'

/// 我认为代码的其余部分将是相同的

【讨论】:

    猜你喜欢
    • 2013-04-08
    • 1970-01-01
    • 2015-06-13
    • 1970-01-01
    • 1970-01-01
    • 2020-03-06
    • 2020-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多