Link Search Menu Expand Document

Take Screenshots During Video Recording - C#

Screen Capturing SDK sample in C# demonstrating ‘Take Screenshots During Video Recording’

Form1.Designer.cs
namespace ScreenCapturingExample
{
	partial class Form1
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}

		#region Windows Form Designer generated code

		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.buttonStart = new System.Windows.Forms.Button();
			this.buttonStop = new System.Windows.Forms.Button();
			this.buttonScreenshot = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// buttonStart
			// 
			this.buttonStart.Location = new System.Drawing.Point(28, 26);
			this.buttonStart.Name = "buttonStart";
			this.buttonStart.Size = new System.Drawing.Size(75, 23);
			this.buttonStart.TabIndex = 0;
			this.buttonStart.Text = "Start";
			this.buttonStart.UseVisualStyleBackColor = true;
			this.buttonStart.Click += new System.EventHandler(this.buttonStart_Click);
			// 
			// buttonStop
			// 
			this.buttonStop.Enabled = false;
			this.buttonStop.Location = new System.Drawing.Point(28, 55);
			this.buttonStop.Name = "buttonStop";
			this.buttonStop.Size = new System.Drawing.Size(75, 23);
			this.buttonStop.TabIndex = 1;
			this.buttonStop.Text = "Stop";
			this.buttonStop.UseVisualStyleBackColor = true;
			this.buttonStop.Click += new System.EventHandler(this.buttonStop_Click);
			// 
			// buttonScreenshot
			// 
			this.buttonScreenshot.Enabled = false;
			this.buttonScreenshot.Location = new System.Drawing.Point(109, 38);
			this.buttonScreenshot.Name = "buttonScreenshot";
			this.buttonScreenshot.Size = new System.Drawing.Size(100, 23);
			this.buttonScreenshot.TabIndex = 2;
			this.buttonScreenshot.Text = "Take Screenshot";
			this.buttonScreenshot.UseVisualStyleBackColor = true;
			this.buttonScreenshot.Click += new System.EventHandler(this.buttonScreenshot_Click);
			// 
			// Form1
			// 
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.ClientSize = new System.Drawing.Size(234, 111);
			this.Controls.Add(this.buttonScreenshot);
			this.Controls.Add(this.buttonStop);
			this.Controls.Add(this.buttonStart);
			this.Name = "Form1";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Form1";
			this.ResumeLayout(false);

		}

		#endregion

		private System.Windows.Forms.Button buttonStart;
		private System.Windows.Forms.Button buttonStop;
		private System.Windows.Forms.Button buttonScreenshot;
	}
}


Form1.cs
using System.Windows.Forms;
using BytescoutScreenCapturingLib;

// NOTE: if you are getting error like "invalid image" related to loading the SDK's dll then 
// try to do the following:
// 1) remove the reference to the SDK by View - Solution Explorer
// then click on References, select Bytescout... reference name and right-click it and select Remove
// 2) To re-add click on the menu: Project - Add Reference
// 3) In "Add Reference" dialog switch to "COM" tab and find "BytescoutScreenCapturing 1.0 Type Library"
// 4) Select it and click "Add" 
// 5) Recompile the application 
// Note: if you need to run on both x64 and x86 then please make sure you have set "Embed Interop Types" to True for this reference

namespace ScreenCapturingExample
{
	public partial class Form1 : Form
	{
		private Capturer _capturer = null;

		private int _screencastCount = 0;
		private int _screenshotCount = 0;

		public Form1()
		{
			InitializeComponent();

			// Create and setup Capturer object:

			_capturer = new Capturer();

			// Capture the full screen
			_capturer.CapturingType = CaptureAreaType.catScreen;

			// Set movie width and height to the current monitor dimensions
			_capturer.OutputWidth = _capturer.MonitorWidth;
			_capturer.OutputHeight = _capturer.MonitorHeight;

			// Setup screenshots
			_capturer.ScreenshotImageFormat = ScreenshotImageType.ssitPng; // Save images in PNG format
			_capturer.ScreenshotOutputFolder = "\\."; // Save to the current folder
			_capturer.ScreenshotSavingType = ScreenshotSavingType.ssstManual; // Take screenshots manually
		}

		private void buttonStart_Click(object sender, System.EventArgs e)
		{
			string fileName = string.Format("screencast{0}.wmv", ++_screencastCount);

			// Start screen recording
			_capturer.OutputFileName = fileName;
			_capturer.Run();

			buttonStart.Enabled = false;
			buttonStop.Enabled = true;
			buttonScreenshot.Enabled = true;
		}

		private void buttonStop_Click(object sender, System.EventArgs e)
		{
			// Stop recording
			_capturer.Stop();

			buttonStart.Enabled = true;
			buttonStop.Enabled = false;
			buttonScreenshot.Enabled = false;

			MessageBox.Show("Screencast saved to " + _capturer.OutputFileName, ProductName);
		}

		private void buttonScreenshot_Click(object sender, System.EventArgs e)
		{
			string fileName = string.Format("screenshot{0}.png", ++_screenshotCount);

			// Take screenshot during the recording
			_capturer.TakeScreenshot(fileName);

			MessageBox.Show("Screenshot saved to " + fileName, ProductName);
		}
	}
}

Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace ScreenCapturingExample
{
	static class Program
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main()
		{
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
			Application.Run(new Form1());
		}
	}
}

Resources.Designer.cs
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace TakeScreenshotsDuringRecording.Properties {
    using System;
    
    
    /// <summary>
    ///   A strongly-typed resource class, for looking up localized strings, etc.
    /// </summary>
    // This class was auto-generated by the StronglyTypedResourceBuilder
    // class via a tool like ResGen or Visual Studio.
    // To add or remove a member, edit your .ResX file then rerun ResGen
    // with the /str option, or rebuild your VS project.
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    internal class Resources {
        
        private static global::System.Resources.ResourceManager resourceMan;
        
        private static global::System.Globalization.CultureInfo resourceCulture;
        
        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        internal Resources() {
        }
        
        /// <summary>
        ///   Returns the cached ResourceManager instance used by this class.
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Resources.ResourceManager ResourceManager {
            get {
                if (object.ReferenceEquals(resourceMan, null)) {
                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TakeScreenshotsDuringRecording.Properties.Resources", typeof(Resources).Assembly);
                    resourceMan = temp;
                }
                return resourceMan;
            }
        }
        
        /// <summary>
        ///   Overrides the current thread's CurrentUICulture property for all
        ///   resource lookups using this strongly typed resource class.
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Globalization.CultureInfo Culture {
            get {
                return resourceCulture;
            }
            set {
                resourceCulture = value;
            }
        }
    }
}

Settings.Designer.cs
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace TakeScreenshotsDuringRecording.Properties {
    
    
    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.1.0.0")]
    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
        
        private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
        
        public static Settings Default {
            get {
                return defaultInstance;
            }
        }
    }
}

Download Source Code (.zip)

Return to the previous page Explore Screen Capturing SDK