Ejemplo n.º 1
0
 public bool StartVideo(DeviceInfo device, DeviceCapabilityInfo info)
 {
     try
     {
         Size frameSize = info.FrameSize;
         int rate = info.MaxFrameRate;
         videoSource = new VideoCaptureDevice(device.MonikerString);
         videoSource.DesiredFrameSize = frameSize;
         videoSource.DesiredFrameRate = rate;
         videoSource.NewFrame += new AForge.Video.NewFrameEventHandler(videoSource_NewFrame);
         videoSource.Start();
         DeviceExist = true;
         return true;
     }
     catch
     {
         return false;
     }
 }
Ejemplo n.º 2
0
        private void frmCamera_Load(object sender, EventArgs e)
        {
            while (cConfig.CameraIndex < 0 || cConfig.resolutionIndex < 0)
            {
                if (frmSetting.isClose)
                { break; }
                using (frmSetting fs = new frmSetting())
                {
                    fs.ShowDialog();
                }

            }

            if (frmSetting.isClose)
            { this.Close(); return; }

            ls2.Clear();
            _DeviceCapabilityInfo = null;
            _DeviceInfo = ls1[cConfig.CameraIndex];
            foreach (DeviceCapabilityInfo info in camera.GetDeviceCapability(_DeviceInfo))
            {
                ls2.Add(info);
            }

            _DeviceCapabilityInfo = ls2[cConfig.resolutionIndex];

            if (_DeviceInfo != null && _DeviceCapabilityInfo != null)
            {
                if (camera.StartVideo(_DeviceInfo, _DeviceCapabilityInfo))
                {
                    btnphotograph.Enabled = true;
                }
            }
            toolStripStatusLabel1.Text = "工作中......";
            pictureBox2.Visible = false;
        }
Ejemplo n.º 3
0
 public List<DeviceCapabilityInfo> GetDeviceCapability(DeviceInfo deviceInfo)
 {
     List<DeviceCapabilityInfo> deviceCapability = new List<DeviceCapabilityInfo>();
     VideoCaptureDevice video = new VideoCaptureDevice(deviceInfo.MonikerString);
     for (int i = 0; i < video.VideoCapabilities.Length; i++)
     {
         VideoCapabilities cap = video.VideoCapabilities[i];
         DeviceCapabilityInfo capInfo = new DeviceCapabilityInfo(cap.FrameSize, cap.FrameRate);
         deviceCapability.Add(capInfo);
     }
     return deviceCapability;
 }