Click here to Skip to main content
15,892,480 members
Articles / Multimedia / GDI+

Webcamera, Multithreading and VFW

Rate me:
Please Sign up or sign in to vote.
4.79/5 (22 votes)
15 Feb 2008CPOL5 min read 234.1K   9.5K   137  
An article on webcamera frame-grabbing in a multi-thread environment
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;

namespace SevenZ.WebCamera
{
   public class Device
   {
      public string Name;
      public string Version;

      public Device(string name, string version)
      {
         this.Name = name; this.Version = version;
      }

      public override string ToString()
      {
         return Name + "  " + Version;
      }
      
   }

   public class WebCameraDeviceManager
   {
      [DllImport("avicap32.dll")]
      static extern bool capGetDriverDescription(int wDriverIndex,
          [MarshalAs(UnmanagedType.VBByRefStr)]ref String lpszName,
          int cbName, [MarshalAs(UnmanagedType.VBByRefStr)] ref String lpszVer, int cbVer);
      
      List<Device> devices = new List<Device>(10);

      public WebCameraDeviceManager()
      {
         Refresh();
      }

      public void Refresh()
      {
         string name = "".PadRight(100), version = "".PadRight(100);

         for (int i = 0; i < 10; i++)
         {
            if (capGetDriverDescription(i, ref name, 100, ref version, 100))
            {
               Device d = new Device(name,version);
               d.Name = name.Trim();
               d.Version = version.Trim();
               devices.Add(d);
            }
         }
      }

      public Device Device(int index)
      {
         return devices[index];
      }

      public Device[] Devices
      {
         get { return devices.ToArray(); }
      }
   }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Finland Finland
I'm a Master degree student, studying at the University of Joensuu, Finland.

Comments and Discussions