Exemplo n.º 1
0
        private void VideoFrameArrived(object sender, DeckLinkVideoFrameArrivedEventArgs e)
        {
            checkBoxInputValid.Checked = !e.inputInvalid;

            if (e.inputInvalid)
            {
                if (++m_invalidFrameTimeout == kInputInvalidFrameTimeout)
                {
                    if (MessageBox.Show("Timeout waiting for valid input signal.", "Invalid frame timeout") == DialogResult.OK)
                    {
                        if (m_captureInvalidCancel != null)
                        {
                            m_captureInvalidCancel.Cancel();
                        }
                    }
                }
            }
            else if (++m_captureFrameIntervalCount == numericUpDownCaptureFrameInterval.Value)
            {
                IntPtr bgra32FrameBytes;
                String outputFileName = m_selectedFolder + "\\image_" + m_captureStillsCount.ToString("D4") + "." + comboBoxFileType.SelectedItem.ToString().ToLower();

                if (File.Exists(outputFileName))
                {
                    if (MessageBox.Show("File " + outputFileName + " already exists, stopping capture", "File Exists") == DialogResult.OK)
                    {
                        if (m_captureFileExists != null)
                        {
                            m_captureFileExists.Cancel();
                        }
                        return;
                    }
                }

                IDeckLinkVideoFrame bgra32Frame = m_frameConverter.ConvertFrame(e.videoFrame);
                bgra32Frame.GetBytes(out bgra32FrameBytes);

                using (Bitmap bgra32Bitmap = new Bitmap(bgra32Frame.GetWidth(), bgra32Frame.GetHeight(), bgra32Frame.GetRowBytes(), PixelFormat.Format32bppArgb, bgra32FrameBytes))
                {
                    bgra32Bitmap.Save(outputFileName, (ImageFormat)comboBoxFileType.SelectedItem);
                }

                m_captureFrameIntervalCount = 0;
                m_captureStillsCount++;

                if (m_captureCountdown != null)
                {
                    m_captureCountdown.Signal();
                }
            }
        }