} /// <summary> /// Captures a frame. /// </summary> /// <param name="region"> /// The region. /// </param> /// <returns> /// A bitmap containing the captured frame. /// </returns> public Bitmap CaptureFrame(ScreenRecorderOptions recordOption) { Rectangle region = recordOption.RecordingRegion; // Create a new bitmap. var frameBitmap = new Bitmap( region.Width, region.Height, PixelFormat.Format32bppArgb); // Create a graphics object from the bitmap. using (var gfxScreenshot = Graphics.FromImage(frameBitmap)) { // Take the screenshot from the upper left corner to the right bottom corner. gfxScreenshot.CopyFromScreen( region.X, region.Y, 0, 0, region.Size, CopyPixelOperation.SourceCopy); Point position = Cursor.Position; var x = position.X; var y = position.Y; var cursorBmp = CursorHelper.CaptureCursor(ref x, ref y); // We need to offset the cursor position by the region, to position it correctly // in the image. position = new Point( x - region.X, y - region.Y); if (cursorBmp != null) { gfxScreenshot.DrawImage(cursorBmp, position); } cursorBmp.Dispose(); } return(frameBitmap); }
/// <summary> /// Starts the recording. /// </summary> public void StartRecording() { this.notifyIcon.HideBalloonTip(); this.IsRecording = true; var fileName = string.Format("Recording {0}.mp4", DateTime.Now.ToString("yy-MM-dd HH-mm-ss")); var outputFilePath = Path.Combine(this.settings.StoragePath, fileName); this.fileViewModel = new ScreenGunFileViewModel(outputFilePath, RecordingStage.DoingNothing); var opts = new ScreenRecorderOptions(this.RecordingRegion) { DeleteMaterialWhenDone = true, OutputFilePath = outputFilePath, RecordMicrophone = this.UseMicrophone, AudioRecordingDeviceNumber = this.settings.RecordingDeviceNumber }; var progress = new Progress <RecorderState>(state => this.fileViewModel.RecordingStage = state.Stage); this.recorder.Start(opts, progress); }
/// <summary> /// Starts recording. Does not block. /// </summary> /// <param name="options"> /// The recorder options. /// </param> /// <param name="progressReporter"> /// The progress reporter, if any.. /// </param> public void Start(ScreenRecorderOptions options, IProgress <RecorderState> progressReporter = null) { if (IsRecording) { throw new ScreenRecorderException("Already recording."); } recorderOptions = options; progress = progressReporter; frameSaverTasks.Clear(); frames = new ConcurrentQueue <Frame>(); recordingName = string.Format("Recording {0}", DateTime.Now.ToString("yy-MM-dd HH-mm-ss")); materialFolder = Path.Combine(recorderOptions.MaterialTempFolder, recordingName); if (Directory.Exists(materialFolder)) { Directory.Delete(micFilePath, true); } Directory.CreateDirectory(materialFolder); micFilePath = Path.Combine(materialFolder, "Microphone.wav"); recordingStartedAt = DateTime.Now; Task.Run((Action)Record); }