示例#1
0
        private void btnRecord_Click(object sender, EventArgs e)
        {
            try
            {
                if (_capturer.IsRunning)
                {
                    _capturer.Stop();
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(_capturer);
                    _capturer = null;
                    InitCapturer();

                    lstOverlays.Items.Clear();
                    btnRecord.Text        = "Record";
                    grpProperties.Enabled = true;
                    lblStatus.Text        = "Stopped";
                }
                else
                {
                    _capturer.AudioEnabled = chkEnableAudio.Checked;
                    if (chkEnableAudio.Checked)
                    {
                        _capturer.CurrentAudioDeviceName = cmbAudioDevices.SelectedItem.ToString();
                        //_capturer.CurrentAudioCodecName = cmbAudioCodecs.SelectedItem.ToString();
                    }

                    _capturer.AddWebCamVideo = chkEnableWebcam.Checked;
                    if (chkEnableWebcam.Checked)
                    {
                        _capturer.SetWebCamVideoRectangle((int)nmWebCamLeft.Value, (int)nmWebCamTop.Value, (int)nmWebCamWidth.Value, (int)nmWebCamHeight.Value);
                        _capturer.CurrentWebCamName = cmbWebCam.SelectedItem.ToString();
                    }

                    //_capturer.CurrentVideoCodecName = cmbVideoCodec.SelectedItem.ToString();

                    if (!string.IsNullOrEmpty(txtLogFile.Text))
                    {
                        _capturer.SetLogFile(txtLogFile.Text);
                    }

                    _capturer.OutputFileName = txtOutputFile.Text;

                    _capturer.CapturingType = (CaptureAreaType)cmbCaptureAreaType.SelectedItem;

                    _previewGraphics = pnlPreview.CreateGraphics();
                    _previewHdc      = _previewGraphics.GetHdc().ToInt32();
                    _capturer.SetFullPreviewContext(_previewHdc, 0, 0, pnlPreview.Width, pnlPreview.Height, 5);

                    _capturer.CaptureRectLeft   = (int)nmCaptureLeft.Value;
                    _capturer.CaptureRectTop    = (int)nmCaptureTop.Value;
                    _capturer.CaptureRectWidth  = (int)nmCaptureWidth.Value;
                    _capturer.CaptureRectHeight = (int)nmCaptureHeight.Value;

                    _capturer.OutputWidth  = (int)nmOutputWidth.Value;
                    _capturer.OutputHeight = (int)nmOutputHeight.Value;


                    foreach (ListViewItem item in lstOverlays.Items)
                    {
                        Overlay overlay = item.Tag as Overlay;
                        if (overlay is TextOverlay)
                        {
                            TextOverlay textOverlay = overlay as TextOverlay;

                            int a = (int)textOverlay.BackColor.A;
                            //_capturer.AddTextOverlay(textOverlay.Left, textOverlay.Top, textOverlay.Text, textOverlay.Font.Name,
                            //                        (int)textOverlay.Font.Size,textOverlay.Font.Bold, textOverlay.Font.Italic,
                            //                        textOverlay.Font.Underline, (uint)ColorTranslator.ToOle(textOverlay.Color));
                            _capturer.AddTextOverlayWithBackground2(textOverlay.Left, textOverlay.Top, textOverlay.Text, textOverlay.Font.Name,
                                                                    (int)textOverlay.Font.Size, textOverlay.Font.Bold, textOverlay.Font.Italic,
                                                                    textOverlay.Font.Underline,
                                                                    textOverlay.Color.R, textOverlay.Color.G, textOverlay.Color.B, textOverlay.Color.A,
                                                                    textOverlay.BackColor.R, textOverlay.BackColor.G, textOverlay.BackColor.B, textOverlay.BackColor.A);
                        }
                        else if (overlay is ImageOverlay)
                        {
                            ImageOverlay imageOverlay = overlay as ImageOverlay;
                            _capturer.AddImageOverlay(imageOverlay.Left, imageOverlay.Top, imageOverlay.FileName);
                        }
                    }


                    _capturer.Run();

                    //' IMPORTANT: if you want to check for some code if need to stop the recording then make sure you are
                    //' using Thread.Sleep(1) inside the checking loop, so you have the loop like
                    //' Do {
                    //' Thread.Sleep(1)
                    //' }
                    //' While(StopButtonNotClicked);


                    btnRecord.Text        = "Stop";
                    grpProperties.Enabled = false;
                    lblStatus.Text        = "Running";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#2
0
        private void btnRecord_Click(object sender, EventArgs e)
        {
            try
            {
                if (_capturer.IsRunning)
                {
                    _capturer.Stop();
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(_capturer);
                    _capturer = null;
                    InitCapturer();

                    // lstOverlays.Items.Clear();
                    btnRecord.Text      = "Record";
                    tabControl1.Enabled = true;
                    lblStatus.Text      = "Stopped";
                    timer1.Stop();
                    _captureStarted = false;

                    btnPause.Enabled = false;
                    _isPaused        = false;
                }
                else
                {
                    if (!_isPaused)
                    {
                        _capturer.AudioEnabled = chkEnableAudio.Checked;
                        if (chkEnableAudio.Checked)
                        {
                            _capturer.CurrentAudioDeviceName = cmbAudioDevices.SelectedItem.ToString();
                            //_capturer.CurrentAudioCodecName = cmbAudioCodecs.SelectedItem.ToString();
                        }

                        _capturer.AddWebCamVideo = chkEnableWebcam.Checked;
                        if (chkEnableWebcam.Checked)
                        {
                            _capturer.SetWebCamVideoRectangle((int)nmWebCamLeft.Value, (int)nmWebCamTop.Value, (int)nmWebCamWidth.Value, (int)nmWebCamHeight.Value);
                            _capturer.CurrentWebCamName = cmbWebCam.SelectedItem.ToString();
                        }

                        //_capturer.CurrentVideoCodecName = cmbVideoCodec.SelectedItem.ToString();

                        if (!string.IsNullOrEmpty(txtLogFile.Text) && cbWriteLog.Checked)
                        {
                            _capturer.SetLogFile(txtLogFile.Text);
                        }

                        _capturer.OutputFileName = txtOutputFile.Text;

                        _capturer.CapturingType = (CaptureAreaType)cmbCaptureAreaType.SelectedItem;

                        _previewGraphics = pnlPreview.CreateGraphics();
                        _previewHdc      = _previewGraphics.GetHdc().ToInt32();
                        _capturer.SetFullPreviewContext(_previewHdc, 0, 0, pnlPreview.Width, pnlPreview.Height, 5);

                        _capturer.CaptureRectLeft   = (int)nmCaptureLeft.Value;
                        _capturer.CaptureRectTop    = (int)nmCaptureTop.Value;
                        _capturer.CaptureRectWidth  = (int)nmCaptureWidth.Value;
                        _capturer.CaptureRectHeight = (int)nmCaptureHeight.Value;

                        _capturer.OutputWidth  = (int)nmOutputWidth.Value;
                        _capturer.OutputHeight = (int)nmOutputHeight.Value;


                        foreach (ListViewItem item in lstOverlays.Items)
                        {
                            Overlay overlay = item.Tag as Overlay;
                            if (overlay is TextOverlay)
                            {
                                TextOverlay textOverlay = overlay as TextOverlay;

                                int a = (int)textOverlay.BackColor.A;
                                //_capturer.AddTextOverlay(textOverlay.Left, textOverlay.Top, textOverlay.Text, textOverlay.Font.Name,
                                //                        (int)textOverlay.Font.Size,textOverlay.Font.Bold, textOverlay.Font.Italic,
                                //                        textOverlay.Font.Underline, (uint)ColorTranslator.ToOle(textOverlay.Color));
                                _capturer.AddTextOverlayWithBackground2(textOverlay.Left, textOverlay.Top, textOverlay.Text, textOverlay.Font.Name,
                                                                        (int)textOverlay.Font.Size, textOverlay.Font.Bold, textOverlay.Font.Italic,
                                                                        textOverlay.Font.Underline,
                                                                        textOverlay.Color.R, textOverlay.Color.G, textOverlay.Color.B, textOverlay.Color.A,
                                                                        textOverlay.BackColor.R, textOverlay.BackColor.G, textOverlay.BackColor.B, textOverlay.BackColor.A);
                            }
                            else if (overlay is ImageOverlay)
                            {
                                ImageOverlay imageOverlay = overlay as ImageOverlay;
                                _capturer.AddImageOverlay(imageOverlay.Left, imageOverlay.Top, imageOverlay.FileName);
                            }
                        }

                        _capturer.RecordingMode = (RecordingModeType)cmbMotionDetection.SelectedItem;
                        _capturer.NoMotionDetectedActionInterval    = (int)nmMotionInterval.Value;
                        _capturer.NoMotionDetectedActionSensitivity = (double)nmMotionSensitivity.Value;

                        _capturer.MonitorIndex = (int)cmbCurrentMonitor.SelectedItem;
                    }

                    _capturer.Run();


                    btnRecord.Text      = "Stop";
                    tabControl1.Enabled = false;
                    lblStatus.Text      = "Running";
                    _captureStarted     = true;
                    timer1.Start();

                    _isPaused        = false;
                    btnPause.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }