private void btnPauseRecording_Click(object sender, EventArgs e) { bool captureToAvi = (tabControl1.SelectedIndex == 1); if (captureToAvi) { MessageBox.Show("Pausing is only available for WMV format yet."); return; } if (!_paused) { capturer.Pause(); _paused = true; btnPauseRecording.Text = "Resume recodring"; } else { // Resume capturing capturer.Run(); _paused = false; btnPauseRecording.Text = "Pause recording"; } }
public static void ThreadProc(Object obj) { CapturingThreadData data = (CapturingThreadData)obj; data.Success = true; // Prepare Capturer: Capturer capturer = new Capturer(); // create new screen capturer object capturer.RegistrationName = "demo"; capturer.RegistrationKey = "demo"; capturer.CaptureRectLeft = data.CaptureRectangle.Left; capturer.CaptureRectTop = data.CaptureRectangle.Top; capturer.CaptureRectWidth = data.CaptureRectangle.Width; capturer.CaptureRectHeight = data.CaptureRectangle.Height; capturer.OutputWidth = 640; capturer.OutputHeight = 480; // WMV and WEBM output use WMVVideoBitrate property to control output video bitrate // so try to increase it by x2 or x3 times if you think the output video are you are getting is laggy // capturer.WMVVideoBitrate = capturer.WMVVideoBitrate * 2; capturer.CaptureRectWidth = 320; capturer.CaptureRectHeight = 240; data.TempFile = Path.GetTempFileName(); data.TempFile = Path.ChangeExtension(data.TempFile, ".wmv"); capturer.OutputFileName = data.TempFile; capturer.CapturingType = data.CaptureType; // set border around captured area if we are not capturing entire screen if (capturer.CapturingType != CaptureAreaType.catScreen && capturer.CapturingType != CaptureAreaType.catWebcamFullScreen) { capturer.CaptureAreaBorderType = CaptureAreaBorderType.cabtDashed; capturer.CaptureAreaBorderColor = (uint)ColorTranslator.ToOle(Color.Red); } // Wait for events: WaitHandle[] events = new WaitHandle[] { data.StartOrResumeEvent, data.PauseEvent, data.StopEvent }; try { while (true) { int i = WaitHandle.WaitAny(events); if (events[i] == data.StartOrResumeEvent) { if (!capturer.IsRunning) { capturer.Run(); } } else if (events[i] == data.PauseEvent) { if (capturer.IsRunning) { capturer.Pause(); } } else if (events[i] == data.StopEvent) { capturer.Stop(); break; } } } catch (Exception ex) { data.ErrorText = ex.Message; data.Success = false; } finally { // Release resources Marshal.ReleaseComObject(capturer); } }
static void Main(string[] args) { Capturer capturer = new Capturer(); // create new screen capturer object capturer.CapturingType = CaptureAreaType.catScreen; // set capturing area type to catScreen to capture whole screen capturer.OutputFileName = "EntireScreenCaptured.wmv"; // set output video filename to .WMV or .AVI file // set output video width and height capturer.OutputWidth = 640; capturer.OutputHeight = 480; // uncomment to enable recording of semitransparent or layered windows (Warning: may cause mouse cursor flickering) // capturer.CaptureTransparentControls = true; // WMV and WEBM output use WMVVideoBitrate property to control output video bitrate // so try to increase it by x2 or x3 times if you think the output video are you are getting is laggy // capturer.WMVVideoBitrate = capturer.WMVVideoBitrate * 2; // set border around captured area if we are not capturing entire screen if ( capturer.CapturingType != CaptureAreaType.catScreen && capturer.CapturingType != CaptureAreaType.catWebcamFullScreen ) { // set border style capturer.CaptureAreaBorderType = CaptureAreaBorderType.cabtDashed; capturer.CaptureAreaBorderColor = (uint)ColorTranslator.ToOle(Color.Red); } // uncomment to set Bytescout Lossless Video format output video compression method // do not forget to set file to .avi format if you use Video Codec Name // capturer.CurrentVideoCodecName = "Bytescout Lossless"; capturer.Run(); // run screen video capturing // IMPORTANT: if you want to check for some code if need to stop the recording then make sure you are // using Thread.Sleep(1) inside the checking loop, so you have the loop like // Do { // Thread.Sleep(1) // } // While(StopButtonNotClicked); Console.WriteLine("Capturing entire screen for 10 seconds..."); Thread.Sleep(10000); // wait for 10 seconds capturer.Pause(); // pause recording Console.WriteLine("Recording paused. Press any key to resume and record 2nd part..."); Console.ReadKey(); Console.WriteLine("Resuming the recording for another 5 seconds..."); Thread.Sleep(5000); // wait for 5 seconds while recording capturer.Stop(); // finally stop the recording Console.WriteLine("Done! Press any key to exit"); Console.ReadKey(); // Release resources System.Runtime.InteropServices.Marshal.ReleaseComObject(capturer); capturer = null; Console.WriteLine("Done"); Process.Start("EntireScreenCaptured.wmv"); }