public void Start()
 {
     if (!connected)
     {
         try
         {
             TimerResolution.TimeBeginPeriod(1);
             List <string> deviceNames = CaptureDevice.GetDeviceNames();
             int           deviceIndex = deviceNames.IndexOf(deviceName);
             if (deviceIndex >= 0)
             {
                 millisecondSleepInterval = (int)Math.Round(1000 / (double)this.frameRate);
                 List <CameraResolution> cr = CaptureDevice.GetAvailableResolutions(deviceIndex);
                 captureDevice = new CaptureDevice(deviceIndex, this.frameRate, this.ImageWidth, this.ImageHeight);
                 captureDevice.Start();
                 connected = true;
                 OnCameraStarted();
                 //    OnCameraStarted();
                 //     captureDevice.SetVideoProperty(VideoProcAmpProperty.Brightness, 200);
             }
         }
         catch
         {
             connected = false;
         }
     }
     if (connected)
     {
         runThread = new Thread(new ThreadStart(RunLoop));
         runThread.Start();
     }
 }
        private Bitmap ReadFromCaptureDevice(CaptureDevice captureDevice)
        {
            readMutex.WaitOne();
            Bitmap bitmap = null;

            try
            {
                IntPtr imagePointer = captureDevice.GetBitMap();
                int    width        = captureDevice.Width;
                int    height       = captureDevice.Height;
                int    stride       = captureDevice.Stride;
                bitmap = new Bitmap(width, height, stride, PixelFormat.Format24bppRgb, imagePointer);
                bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);
                Marshal.FreeCoTaskMem(imagePointer);
            }
            catch
            {
                string errorString = "Failed to read image";
            }
            readMutex.ReleaseMutex();
            return(bitmap);
        }
 public static List <string> GetDeviceNames()
 {
     return(CaptureDevice.GetDeviceNames());
 }