Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Screen Recorder

0.00/5 (No votes)
4 Oct 2016 1  
Create a screen recorder using C#

Introduction

In this tip, we create a customized screen recorder using C#.NET.

Background

At work, we wanted a screen recorder to record the procedure. Unfortunately, we don't have any screen recorder. So I developed a screen recorder in C# to record our screen.

Using the Code

At first, create a source and install Accord.Video.FFMPEG from nuget library.

Screen recorder is created by a timer and VideoFileWriter.

First of all, initialize a timer control and assign properties to the control. Then, create a tick event to that timer .

timer1 = new Timer();
timer1.Interval = 20;
timer1.Tick += timer1_Tick;
vf = new VideoFileWriter();
vf.Open("Exported_Video.avi", 800, 600, 25, VideoCodec.MPEG4, 1000000);

Create a start button to start the timer.

private void button1_Click(object sender, EventArgs e)
{
    timer1.Start();
}

In the timer tick event, create a bitmap image from the size of VideoFileWriter and capture screen and write it to bitmap image. Then, write the image to VideoFileWriter.

private void timer1_Tick(object sender, EventArgs e)
{
    bp = new Bitmap(800, 600);
    gr = Graphics.FromImage(bp);
    gr.CopyFromScreen(0, 0, 0, 0, new Size(bp.Width, bp.Height));
    pictureBox1.Image = bp;
    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
    vf.WriteVideoFrame(bp);
}

Create a stop button to stop the timer and save the file.

private void button2_Click(object sender, EventArgs e)
{
    timer1.Stop();
    vf.Close();
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here