コード例 #1
0
        /// <summary>
        ///   Paints the control.
        /// </summary>
        ///
        /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs"/> that contains the event data.</param>
        ///
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (capture != null)
            {
                capture.Draw(e.Graphics);
            }
        }
コード例 #2
0
        void VideoPlayer_NewFrameReceived(object sender, Accord.Video.NewFrameEventArgs eventArgs)
        {
            DateTime currentFrameTime = eventArgs.CaptureFinished;

            // Encode the last frame at the same time we prepare the new one
            Task.WaitAll(
                Task.Run(() =>
            {
                lock (syncObj)     // Save the frame to the video file.
                {
                    if (IsRecording)
                    {
                        if (RecordingStartTime == DateTime.MinValue)
                        {
                            RecordingStartTime = DateTime.Now;
                        }

                        TimeSpan timestamp = currentFrameTime - RecordingStartTime;
                        if (timestamp > TimeSpan.Zero)
                        {
                            videoWriter.WriteVideoFrame(this.lastFrame, timestamp, this.lastFrameRegion);
                        }
                    }
                }
            }),

                Task.Run(() =>
            {
                // Adjust the window according to the current capture
                // mode. Also adjusts to keep even widths and heights.
                CaptureRegion = AdjustWindow();

                // Crop the image if the mode requires it
                if (CaptureMode == CaptureRegionOption.Fixed ||
                    CaptureMode == CaptureRegionOption.Window)
                {
                    crop.Rectangle = CaptureRegion;

                    eventArgs.Frame     = croppedImage = crop.Apply(eventArgs.Frame, croppedImage);
                    eventArgs.FrameSize = crop.Rectangle.Size;
                }

                //// Draw extra information on the screen
                bool captureMouse = Settings.Default.CaptureMouse;
                bool captureClick = Settings.Default.CaptureClick;
                bool captureKeys  = Settings.Default.CaptureKeys;

                if (captureMouse || captureClick || captureKeys)
                {
                    cursorCapture.CaptureRegion = CaptureRegion;
                    clickCapture.CaptureRegion  = CaptureRegion;
                    keyCapture.Font             = Settings.Default.KeyboardFont;

                    using (Graphics g = Graphics.FromImage(eventArgs.Frame))
                    {
                        g.CompositingQuality = CompositingQuality.HighSpeed;
                        g.SmoothingMode      = SmoothingMode.HighSpeed;

                        float invWidth  = 1;    // / widthScale;
                        float invHeight = 1;    // / heightScale;

                        if (captureMouse)
                        {
                            cursorCapture.Draw(g, invWidth, invHeight);
                        }

                        if (captureClick)
                        {
                            clickCapture.Draw(g, invWidth, invHeight);
                        }

                        if (captureKeys)
                        {
                            keyCapture.Draw(g, invWidth, invHeight);
                        }
                    }
                }
            })
                );

            // Save the just processed frame and mark
            // it to be encoded in the next iteration:
            lastFrame = eventArgs.Frame.Copy(lastFrame);
            //lastFrameTime = currentFrameTime;
            lastFrameRegion = new Rectangle(0, 0, eventArgs.FrameSize.Width, eventArgs.Frame.Height);
        }
コード例 #3
0
        private void Player_NewFrame(object sender, ref Bitmap image)
        {
            // Adjust the window according to the current capture
            // mode. Also adjusts to keep even widths and heights.
            CaptureRegion = adjustWindow();

            // Crop the image if the mode requires it
            if (CaptureMode == CaptureRegionOption.Fixed ||
                CaptureMode == CaptureRegionOption.Window)
            {
                crop.Rectangle = CaptureRegion;
                using (Bitmap oldImage = image)
                {
                    image = crop.Apply(oldImage);
                }
            }

            // Draw extra information on the screen
            bool captureMouse = Settings.Default.CaptureMouse;
            bool captureClick = Settings.Default.CaptureClick;
            bool captureKeys  = Settings.Default.CaptureKeys;

            if (captureMouse || captureClick || captureKeys)
            {
                cursorCapture.CaptureRegion = CaptureRegion;
                clickCapture.CaptureRegion  = CaptureRegion;
                keyCapture.Font             = Settings.Default.KeyboardFont;

                using (Graphics g = Graphics.FromImage(image))
                {
                    g.CompositingQuality = CompositingQuality.HighQuality;
                    g.SmoothingMode      = SmoothingMode.HighQuality;

                    if (captureMouse)
                    {
                        cursorCapture.Draw(g);
                    }

                    if (captureClick)
                    {
                        clickCapture.Draw(g);
                    }

                    if (captureKeys)
                    {
                        keyCapture.Draw(g);
                    }
                }
            }

            if (IsRecording)
            {
                lock (syncObj) // Save the frame to the video file.
                {
                    if (RecordingStartTime == DateTime.MinValue)
                    {
                        RecordingStartTime = DateTime.Now;
                    }

                    RecordingDuration = DateTime.Now - RecordingStartTime;

                    // We can't write too fast to the buffer. A better buffer control
                    // needs to be implemented in the future so we can drop frames as
                    // necessary.

                    if (RecordingDuration.Subtract(lastFrameTime).Milliseconds > 10)
                    {
                        videoWriter.WriteVideoFrame(image, RecordingDuration);
                        lastFrameTime = RecordingDuration;
                    }
                }
            }
        }