C# 与 Microsoft Expression Encoder实现屏幕录制

在日常开发中,我们会经常遇到屏幕录制的需求。在C#中可以通过Expression Encoder的SDK实现这样的需求。首先需要下载Expression Encoder SDK,实现代码:

        private ScreenCaptureJob job = null;
        public MainWindow()
        {
            InitializeComponent();
            job = new ScreenCaptureJob();
            job.CaptureMouseCursor = false;
        }

        private void BtnPlay_Click(object sender, RoutedEventArgs e)
        {
            BtnPause.IsEnabled = true;
            BtnStop.IsEnabled = true;
            BtnPlay.IsEnabled = false;
            if(job.Status == RecordStatus.NotStarted)
            {
                job.CaptureRectangle = Screen.PrimaryScreen.WorkingArea;
                job.OutputPath = "D:/ScreenCapture"; 
            }

            job.Start();
        }

        private void BtnPause_Click(object sender, RoutedEventArgs e)
        {
            BtnPlay.IsEnabled = true;
            BtnPause.IsEnabled = false;

            job.Pause();
        }

        private void BtnStop_Click(object sender, RoutedEventArgs e)
        {
            BtnPlay.IsEnabled = true;
            BtnPause.IsEnabled = false;
            BtnStop.IsEnabled = false;
            job.Stop();
        }

        private void OnClosing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (job.Status == RecordStatus.Running)
            {
                MessageBoxResult result =
                    System.Windows.MessageBox.Show("Capturing in Progress. Are You Sure You Want To Quit?", "Capturing",
                    MessageBoxButton.YesNo);
                if (result == MessageBoxResult.No)
                {
                    e.Cancel = true;
                    return;
                }
                job.Stop();
                job.Dispose();
            }
        }

 

参考文档:http://msdn.microsoft.com/en-us/library/gg602440(v=expression.40).aspx

代码下载.

如果你对这个例子有疑问,欢迎在评论中指出;如果有其他实现方法,也欢迎你与我分享。谢谢!

C# 与 Microsoft Expression Encoder实现屏幕录制

上一篇:WPF ListBox数据绑定


下一篇:Windwos7 使用Aero peek预览桌面 灰色不能选择