public static bool GetRectangleRegion(out Rectangle rect, RegionCaptureOptions options) { RegionCaptureOptions newOptions = GetRegionCaptureOptions(options); using (RegionCaptureForm form = new RegionCaptureForm(RegionCaptureMode.Default, newOptions)) { form.ShowDialog(); if (form.Result == RegionResult.Region) { if (form.ShapeManager.IsCurrentShapeValid) { rect = CaptureHelpers.ClientToScreen(form.ShapeManager.CurrentRectangle); return(true); } } else if (form.Result == RegionResult.Fullscreen) { rect = CaptureHelpers.GetScreenBounds(); return(true); } else if (form.Result == RegionResult.Monitor) { Screen[] screens = Screen.AllScreens; if (form.MonitorIndex < screens.Length) { Screen screen = screens[form.MonitorIndex]; rect = screen.Bounds; return(true); } } else if (form.Result == RegionResult.ActiveMonitor) { rect = CaptureHelpers.GetActiveScreenBounds(); return(true); } } rect = Rectangle.Empty; return(false); }
public RegionCaptureLightForm(Screenshot screenshot) { backgroundImage = screenshot.CaptureFullscreen(); backgroundBrush = new TextureBrush(backgroundImage); borderDotPen = new Pen(Color.Black, 1); borderDotPen2 = new Pen(Color.White, 1); borderDotPen2.DashPattern = new float[] { 5, 5 }; penTimer = Stopwatch.StartNew(); ScreenRectangle = CaptureHelpers.GetScreenBounds(); InitializeComponent(); Icon = ShareXResources.Icon; Cursor = Helpers.CreateCursor(Resources.Crosshair); timer = new Timer { Interval = 10 }; timer.Tick += timer_Tick; timer.Start(); }
private void CheckMenuPosition() { Rectangle rectMenu = menuForm.Bounds; Rectangle rectScreen = CaptureHelpers.GetScreenBounds(); Point pos = rectMenu.Location; if (rectMenu.Width < rectScreen.Width) { if (rectMenu.X < rectScreen.X) { pos.X = rectScreen.X; } else if (rectMenu.Right > rectScreen.Right) { pos.X = rectScreen.Right - rectMenu.Width; } } if (rectMenu.Height < rectScreen.Height) { if (rectMenu.Y < rectScreen.Y) { pos.Y = rectScreen.Y; } else if (rectMenu.Bottom > rectScreen.Bottom) { pos.Y = rectScreen.Bottom - rectMenu.Height; } } if (pos != rectMenu.Location) { menuForm.Location = pos; } if (Config.RememberMenuState) { Config.MenuPosition = pos; } }
private void ConfigureMenuPosition() { Rectangle rectScreen = CaptureHelpers.GetScreenBounds(); if (Config.RememberMenuPosition && rectScreen.Contains(Config.MenuPosition)) { menuForm.Location = Config.MenuPosition; } else { Rectangle rectActiveScreen = CaptureHelpers.GetActiveScreenBounds(); if (tsMain.Width < rectActiveScreen.Width) { menuForm.Location = new Point(rectActiveScreen.X + rectActiveScreen.Width / 2 - tsMain.Width / 2, rectActiveScreen.Y + 20); } else { menuForm.Location = rectActiveScreen.Location; } } }
public Surface() { ScreenRectangle = CaptureHelpers.GetScreenBounds(); ScreenRectangle0Based = CaptureHelpers.ScreenToClient(ScreenRectangle); InitializeComponent(); using (MemoryStream cursorStream = new MemoryStream(Resources.Crosshair)) { Cursor = new Cursor(cursorStream); } DrawableObjects = new List <DrawableObject>(); Config = new SurfaceOptions(); timer = new Stopwatch(); borderPen = new Pen(Color.Black); borderDotPen = new Pen(Color.White); borderDotPen.DashPattern = new float[] { 5, 5 }; nodeBackgroundBrush = new SolidBrush(Color.White); textFont = new Font("Arial", 17, FontStyle.Bold); }
private void InitializeComponent() { this.SuspendLayout(); this.Bounds = CaptureHelpers.GetScreenBounds(); this.CausesValidation = false; this.ControlBox = true; this.Cursor = Cursors.Cross; this.DoubleBuffered = true; this.FormBorderStyle = FormBorderStyle.None; this.KeyPreview = true; this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "Crop"; this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); this.ShowIcon = false; #if !DEBUG this.TopMost = true; #endif this.ShowInTaskbar = false; this.ResumeLayout(false); this.KeyDown += new KeyEventHandler(Crop2_KeyDown); }
public RectangleLight() { backgroundImage = Screenshot.CaptureFullscreen(); backgroundBrush = new TextureBrush(backgroundImage); borderDotPen = new Pen(Color.Black, 1); borderDotPen2 = new Pen(Color.White, 1); borderDotPen2.DashPattern = new float[] { 5, 5 }; penTimer = Stopwatch.StartNew(); ScreenRectangle = CaptureHelpers.GetScreenBounds(); InitializeComponent(); using (MemoryStream cursorStream = new MemoryStream(Resources.Crosshair)) { Cursor = new Cursor(cursorStream); } timer = new Timer { Interval = 10 }; timer.Tick += timer_Tick; timer.Start(); }
public RectangleTransparent() { clearPen = new Pen(Color.FromArgb(1, 0, 0, 0)); borderDotPen = new Pen(Color.Black, 1); borderDotPen2 = new Pen(Color.White, 1); borderDotPen2.DashPattern = new float[] { 5, 5 }; penTimer = Stopwatch.StartNew(); ScreenRectangle = CaptureHelpers.GetScreenBounds(); surface = new Bitmap(ScreenRectangle.Width, ScreenRectangle.Height); gSurface = Graphics.FromImage(surface); gSurface.InterpolationMode = InterpolationMode.NearestNeighbor; gSurface.SmoothingMode = SmoothingMode.HighSpeed; gSurface.CompositingMode = CompositingMode.SourceCopy; gSurface.CompositingQuality = CompositingQuality.HighSpeed; gSurface.Clear(Color.FromArgb(1, 0, 0, 0)); StartPosition = FormStartPosition.Manual; Bounds = ScreenRectangle; Text = "ShareX - " + Resources.RectangleTransparent_RectangleTransparent_Rectangle_capture_transparent; Shown += RectangleLight_Shown; KeyUp += RectangleLight_KeyUp; MouseDown += RectangleLight_MouseDown; MouseUp += RectangleLight_MouseUp; using (MemoryStream cursorStream = new MemoryStream(Resources.Crosshair)) { Cursor = new Cursor(cursorStream); } timer = new Timer { Interval = 10 }; timer.Tick += timer_Tick; timer.Start(); }
public Image Capture(Rectangle r, IntPtr handle, bool captureCursor) { Rectangle bounds = CaptureHelpers.GetScreenBounds(); return(TypeRectangle.Capture(bounds)); }
public static Image CaptureWindowTransparent(IntPtr handle) { if (handle.ToInt32() > 0) { Rectangle rect = CaptureHelpers.GetWindowRectangle(handle); Bitmap whiteBackground = null, blackBackground = null, whiteBackground2 = null; MyCursor cursor = null; bool isTransparent = false; try { if (DrawCursor) { cursor = NativeMethods.CaptureCursor(); } using (Form form = new Form()) { form.BackColor = Color.White; form.FormBorderStyle = FormBorderStyle.None; form.ShowInTaskbar = false; if (CaptureShadow && !NativeMethods.IsZoomed(handle) && NativeMethods.IsDWMEnabled()) { const int offset = 20; rect.Inflate(offset, offset); rect.Intersect(CaptureHelpers.GetScreenBounds()); } NativeMethods.ShowWindow(form.Handle, (int)WindowShowStyle.ShowNormalNoActivate); if (!NativeMethods.SetWindowPos(form.Handle, handle, rect.X, rect.Y, rect.Width, rect.Height, NativeMethods.SWP_NOACTIVATE)) { form.Close(); DebugHelper.WriteLine("Transparent capture failed. Reason: SetWindowPos fail."); return(CaptureWindow(handle)); } Thread.Sleep(10); Application.DoEvents(); whiteBackground = (Bitmap)Screenshot.CaptureRectangleNative(rect); form.BackColor = Color.Black; Application.DoEvents(); blackBackground = (Bitmap)Screenshot.CaptureRectangleNative(rect); form.BackColor = Color.White; Application.DoEvents(); whiteBackground2 = (Bitmap)Screenshot.CaptureRectangleNative(rect); form.Close(); } Bitmap transparentImage; if (IsImagesEqual(whiteBackground, whiteBackground2)) { transparentImage = CreateTransparentImage(whiteBackground, blackBackground); isTransparent = true; } else { DebugHelper.WriteLine("Transparent capture failed. Reason: Images not equal."); transparentImage = whiteBackground2; } if (cursor != null) { Point cursorOffset = CaptureHelpers.FixScreenCoordinates(rect.Location); CaptureHelpers.DrawCursorToImage(cursor, transparentImage, cursorOffset); } if (isTransparent) { transparentImage = TrimTransparent(transparentImage); if (!CaptureShadow) { TrimShadow(transparentImage); } } return(transparentImage); } finally { if (whiteBackground != null) { whiteBackground.Dispose(); } if (blackBackground != null) { blackBackground.Dispose(); } if (isTransparent && whiteBackground2 != null) { whiteBackground2.Dispose(); } if (cursor != null) { cursor.Dispose(); } } } return(null); }
public static Image CaptureWindowTransparent(IntPtr handle) { if (handle.ToInt32() > 0) { Rectangle rect = CaptureHelpers.GetWindowRectangle(handle); if (CaptureShadow && !NativeMethods.IsZoomed(handle) && NativeMethods.IsDWMEnabled()) { rect.Inflate(ShadowOffset, ShadowOffset); rect.Intersect(CaptureHelpers.GetScreenBounds()); } Bitmap whiteBackground = null, blackBackground = null, whiteBackground2 = null; CursorData cursor = null; bool isTransparent = false, isTaskbarHide = false; try { if (AutoHideTaskbar) { isTaskbarHide = NativeMethods.SetTaskbarVisibilityIfIntersect(false, rect); } if (CaptureCursor) { try { cursor = new CursorData(); } catch (Exception e) { DebugHelper.WriteException(e, "Cursor capture failed."); } } using (Form form = new Form()) { form.BackColor = Color.White; form.FormBorderStyle = FormBorderStyle.None; form.ShowInTaskbar = false; form.StartPosition = FormStartPosition.Manual; form.Location = new Point(rect.X, rect.Y); form.Size = new Size(rect.Width, rect.Height); NativeMethods.ShowWindow(form.Handle, (int)WindowShowStyle.ShowNoActivate); if (!NativeMethods.SetWindowPos(form.Handle, handle, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE)) { form.Close(); DebugHelper.WriteLine("Transparent capture failed. Reason: SetWindowPos fail."); return(CaptureWindow(handle)); } Thread.Sleep(10); Application.DoEvents(); whiteBackground = (Bitmap)CaptureRectangleNative(rect); form.BackColor = Color.Black; Application.DoEvents(); blackBackground = (Bitmap)CaptureRectangleNative(rect); form.BackColor = Color.White; Application.DoEvents(); whiteBackground2 = (Bitmap)CaptureRectangleNative(rect); form.Close(); } Bitmap transparentImage; if (ImageHelpers.IsImagesEqual(whiteBackground, whiteBackground2)) { transparentImage = CreateTransparentImage(whiteBackground, blackBackground); isTransparent = true; } else { DebugHelper.WriteLine("Transparent capture failed. Reason: Images not equal."); transparentImage = whiteBackground2; } if (cursor != null && cursor.IsVisible) { Point cursorOffset = CaptureHelpers.ScreenToClient(rect.Location); cursor.DrawCursorToImage(transparentImage, cursorOffset); } if (isTransparent) { transparentImage = TrimTransparent(transparentImage); if (!CaptureShadow) { TrimShadow(transparentImage); } } return(transparentImage); } finally { if (isTaskbarHide) { NativeMethods.SetTaskbarVisibility(true); } if (whiteBackground != null) { whiteBackground.Dispose(); } if (blackBackground != null) { blackBackground.Dispose(); } if (isTransparent && whiteBackground2 != null) { whiteBackground2.Dispose(); } if (cursor != null) { cursor.Dispose(); } } } return(null); }
public static Image CaptureFullscreen() { Rectangle bounds = CaptureHelpers.GetScreenBounds(); return(CaptureRectangle(bounds)); }
private static void StartRecording(ScreenRecordOutput outputType, TaskSettings taskSettings, ScreenRecordStartMethod startMethod = ScreenRecordStartMethod.Region) { if (outputType == ScreenRecordOutput.GIF) { taskSettings.CaptureSettings.FFmpegOptions.VideoCodec = FFmpegVideoCodec.gif; } if (taskSettings.CaptureSettings.FFmpegOptions.IsAnimatedImage) { taskSettings.CaptureSettings.ScreenRecordTwoPassEncoding = true; } int fps; if (taskSettings.CaptureSettings.FFmpegOptions.VideoCodec == FFmpegVideoCodec.gif) { fps = taskSettings.CaptureSettings.GIFFPS; } else { fps = taskSettings.CaptureSettings.ScreenRecordFPS; } DebugHelper.WriteLine("Starting screen recording. Video encoder: \"{0}\", Audio encoder: \"{1}\", FPS: {2}", taskSettings.CaptureSettings.FFmpegOptions.VideoCodec.GetDescription(), taskSettings.CaptureSettings.FFmpegOptions.AudioCodec.GetDescription(), fps); if (!TaskHelpers.CheckFFmpeg(taskSettings)) { return; } if (!taskSettings.CaptureSettings.FFmpegOptions.IsSourceSelected) { MessageBox.Show(Resources.ScreenRecordForm_StartRecording_FFmpeg_video_and_audio_source_both_can_t_be__None__, "ShareX - " + Resources.ScreenRecordForm_StartRecording_FFmpeg_error, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Rectangle captureRectangle = Rectangle.Empty; switch (startMethod) { case ScreenRecordStartMethod.Region: RegionCaptureTasks.GetRectangleRegion(out captureRectangle, taskSettings.CaptureSettings.SurfaceOptions); break; case ScreenRecordStartMethod.ActiveWindow: if (taskSettings.CaptureSettings.CaptureClientArea) { captureRectangle = CaptureHelpers.GetActiveWindowClientRectangle(); } else { captureRectangle = CaptureHelpers.GetActiveWindowRectangle(); } break; case ScreenRecordStartMethod.CustomRegion: captureRectangle = taskSettings.CaptureSettings.CaptureCustomRegion; break; case ScreenRecordStartMethod.LastRegion: captureRectangle = Program.Settings.ScreenRecordRegion; break; } Rectangle screenRectangle = CaptureHelpers.GetScreenBounds(); captureRectangle = Rectangle.Intersect(captureRectangle, screenRectangle); if (taskSettings.CaptureSettings.FFmpegOptions.IsEvenSizeRequired) { captureRectangle = CaptureHelpers.EvenRectangleSize(captureRectangle); } if (IsRecording || !captureRectangle.IsValid() || screenRecorder != null) { return; } Program.Settings.ScreenRecordRegion = captureRectangle; IsRecording = true; string path = ""; bool abortRequested = false; float duration = taskSettings.CaptureSettings.ScreenRecordFixedDuration ? taskSettings.CaptureSettings.ScreenRecordDuration : 0; recordForm = new ScreenRecordForm(captureRectangle, taskSettings, startMethod == ScreenRecordStartMethod.Region, duration); recordForm.StopRequested += StopRecording; recordForm.Show(); Task.Run(() => { try { string extension; if (taskSettings.CaptureSettings.ScreenRecordTwoPassEncoding) { extension = "mp4"; } else { extension = taskSettings.CaptureSettings.FFmpegOptions.Extension; } string filename = TaskHelpers.GetFilename(taskSettings, extension); path = TaskHelpers.HandleExistsFile(taskSettings.CaptureFolder, filename, taskSettings); if (string.IsNullOrEmpty(path)) { abortRequested = true; } if (!abortRequested) { recordForm.ChangeState(ScreenRecordState.BeforeStart); if (taskSettings.CaptureSettings.ScreenRecordAutoStart) { int delay = (int)(taskSettings.CaptureSettings.ScreenRecordStartDelay * 1000); if (delay > 0) { recordForm.InvokeSafe(() => recordForm.StartCountdown(delay)); recordForm.RecordResetEvent.WaitOne(delay); } } else { recordForm.RecordResetEvent.WaitOne(); } if (recordForm.IsAbortRequested) { abortRequested = true; } if (!abortRequested) { ScreencastOptions options = new ScreencastOptions() { IsRecording = true, IsLossless = taskSettings.CaptureSettings.ScreenRecordTwoPassEncoding, FFmpeg = taskSettings.CaptureSettings.FFmpegOptions, FPS = fps, Duration = duration, OutputPath = path, CaptureArea = captureRectangle, DrawCursor = taskSettings.CaptureSettings.ScreenRecordShowCursor }; Screenshot screenshot = TaskHelpers.GetScreenshot(taskSettings); screenshot.CaptureCursor = taskSettings.CaptureSettings.ScreenRecordShowCursor; screenRecorder = new ScreenRecorder(ScreenRecordOutput.FFmpeg, options, screenshot, captureRectangle); screenRecorder.RecordingStarted += () => recordForm.ChangeState(ScreenRecordState.AfterRecordingStart); recordForm.ChangeState(ScreenRecordState.AfterStart); screenRecorder.StartRecording(); if (recordForm.IsAbortRequested) { abortRequested = true; } } } } catch (Exception e) { DebugHelper.WriteException(e); } if (taskSettings.CaptureSettings.ScreenRecordTwoPassEncoding && !abortRequested && screenRecorder != null && File.Exists(path)) { recordForm.ChangeState(ScreenRecordState.Encoding); path = ProcessTwoPassEncoding(path, taskSettings); } if (recordForm != null) { recordForm.InvokeSafe(() => { recordForm.Close(); recordForm.Dispose(); recordForm = null; }); } if (screenRecorder != null) { screenRecorder.Dispose(); screenRecorder = null; if (abortRequested && !string.IsNullOrEmpty(path) && File.Exists(path)) { File.Delete(path); } } }).ContinueInCurrentContext(() => { string customFileName; if (!abortRequested && !string.IsNullOrEmpty(path) && File.Exists(path) && TaskHelpers.ShowAfterCaptureForm(taskSettings, out customFileName, null, path)) { if (!string.IsNullOrEmpty(customFileName)) { string currentFilename = Path.GetFileNameWithoutExtension(path); string ext = Path.GetExtension(path); if (!currentFilename.Equals(customFileName, StringComparison.InvariantCultureIgnoreCase)) { path = Helpers.RenameFile(path, customFileName + ext); } } WorkerTask task = WorkerTask.CreateFileJobTask(path, taskSettings, customFileName); TaskManager.Start(task); } abortRequested = false; IsRecording = false; }); }
public WindowRectangle(IntPtr windowHandle) { handle = windowHandle; bounds = CaptureHelpers.GetScreenBounds(); }
/// <summary>Captures a screenshot of a window using Windows GDI. Captures transparency.</summary> /// <param name="handle">handle of the window to capture</param> /// <returns>the captured window image</returns> private static Image CaptureWindowWithGDI(Workflow wfgdi, IntPtr handle, out Rectangle windowRect) { Image windowImageGdi = null; Bitmap whiteBGImage = null, blackBGImage = null, white2BGImage = null; if (wfgdi.ActiveWindowTryCaptureChildren) { windowRect = new WindowRectangle(handle).CalculateWindowRectangle(); } else { windowRect = CaptureHelpers.GetWindowRectangle(handle); } try { using (new Freeze(wfgdi, handle)) using (Form form = new Form()) { form.BackColor = Color.White; form.FormBorderStyle = FormBorderStyle.None; form.ShowInTaskbar = false; int offset = wfgdi.ActiveWindowIncludeShadows && !NativeMethods.IsWindowMaximized(handle) ? 20 : 0; windowRect.Inflate(offset, offset); windowRect.Intersect(CaptureHelpers.GetScreenBounds()); NativeMethods.ShowWindow(form.Handle, (int)WindowShowStyle.ShowNormalNoActivate); NativeMethods.SetWindowPos(form.Handle, handle, windowRect.X, windowRect.Y, windowRect.Width, windowRect.Height, NativeMethods.SWP_NOACTIVATE); Application.DoEvents(); whiteBGImage = (Bitmap)Screenshot.CaptureRectangleNative2(windowRect); form.BackColor = Color.Black; Application.DoEvents(); blackBGImage = (Bitmap)Screenshot.CaptureRectangleNative2(windowRect); if (!wfgdi.ActiveWindowGDIFreezeWindow) { form.BackColor = Color.White; Application.DoEvents(); white2BGImage = (Bitmap)Screenshot.CaptureRectangleNative2(windowRect); } } if (wfgdi.ActiveWindowGDIFreezeWindow || whiteBGImage.AreBitmapsEqual(white2BGImage)) { windowImageGdi = HelpersLib.GraphicsHelper.Core.ComputeOriginal(whiteBGImage, blackBGImage); } else { windowImageGdi = (Image)whiteBGImage.Clone(); } } finally { if (whiteBGImage != null) { whiteBGImage.Dispose(); } if (blackBGImage != null) { blackBGImage.Dispose(); } if (white2BGImage != null) { white2BGImage.Dispose(); } } if (windowImageGdi != null) { Rectangle windowRectCropped = HelpersLib.GraphicsHelper.Core.GetCroppedArea((Bitmap)windowImageGdi); windowImageGdi = CaptureHelpers.CropImage(windowImageGdi, windowRectCropped); if (wfgdi.DrawCursor) { #if DEBUG DebugHelper.WriteLine("Fixed cursor position (before): " + windowRect.ToString()); #endif windowRect.X += windowRectCropped.X; windowRect.Y += windowRectCropped.Y; #if DEBUG DebugHelper.WriteLine("Fixed cursor position (after): " + windowRect.ToString()); #endif } } return(windowImageGdi); }
private void btnFullscreen_Click(object sender, EventArgs e) { Program.Settings.AutoCaptureRegion = CaptureHelpers.GetScreenBounds(); UpdateRegion(); }
private static void StartRecording(ScreenRecordOutput outputType, TaskSettings taskSettings, ScreenRecordStartMethod startMethod = ScreenRecordStartMethod.Region) { if (outputType == ScreenRecordOutput.FFmpeg && taskSettings.CaptureSettings.FFmpegOptions.VideoCodec == FFmpegVideoCodec.gif) { outputType = ScreenRecordOutput.GIF; } if (outputType == ScreenRecordOutput.FFmpeg) { DebugHelper.WriteLine("Starting screen recording. Video encoder: \"{0}\", Audio encoder: \"{1}\", FPS: {2}", taskSettings.CaptureSettings.FFmpegOptions.VideoCodec.GetDescription(), taskSettings.CaptureSettings.FFmpegOptions.AudioCodec.GetDescription(), taskSettings.CaptureSettings.ScreenRecordFPS); } else { DebugHelper.WriteLine("Starting screen recording. FPS: {0}", taskSettings.CaptureSettings.GIFFPS); } if (taskSettings.CaptureSettings.RunScreencastCLI) { if (!Program.Settings.VideoEncoders.IsValidIndex(taskSettings.CaptureSettings.VideoEncoderSelected)) { MessageBox.Show(Resources.ScreenRecordForm_StartRecording_There_is_no_valid_CLI_video_encoder_selected_, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!Program.Settings.VideoEncoders[taskSettings.CaptureSettings.VideoEncoderSelected].IsValid()) { MessageBox.Show(Resources.ScreenRecordForm_StartRecording_CLI_video_encoder_file_does_not_exist__ + Program.Settings.VideoEncoders[taskSettings.CaptureSettings.VideoEncoderSelected].Path, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } if (outputType == ScreenRecordOutput.GIF) { taskSettings.CaptureSettings.FFmpegOptions.VideoCodec = FFmpegVideoCodec.gif; taskSettings.CaptureSettings.FFmpegOptions.UseCustomCommands = false; } if (!TaskHelpers.CheckFFmpeg(taskSettings)) { return; } if (!taskSettings.CaptureSettings.FFmpegOptions.IsSourceSelected) { MessageBox.Show(Resources.ScreenRecordForm_StartRecording_FFmpeg_video_and_audio_source_both_can_t_be__None__, "ShareX - " + Resources.ScreenRecordForm_StartRecording_FFmpeg_error, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Rectangle captureRectangle = Rectangle.Empty; switch (startMethod) { case ScreenRecordStartMethod.Region: RegionCaptureTasks.GetRectangleRegion(out captureRectangle, taskSettings.CaptureSettings.SurfaceOptions); break; case ScreenRecordStartMethod.ActiveWindow: if (taskSettings.CaptureSettings.CaptureClientArea) { captureRectangle = CaptureHelpers.GetActiveWindowClientRectangle(); } else { captureRectangle = CaptureHelpers.GetActiveWindowRectangle(); } break; case ScreenRecordStartMethod.CustomRegion: captureRectangle = taskSettings.CaptureSettings.CaptureCustomRegion; break; case ScreenRecordStartMethod.LastRegion: captureRectangle = Program.Settings.ScreenRecordRegion; break; } Rectangle screenRectangle = CaptureHelpers.GetScreenBounds(); captureRectangle = Rectangle.Intersect(captureRectangle, screenRectangle); if (outputType != ScreenRecordOutput.GIF) { captureRectangle = CaptureHelpers.EvenRectangleSize(captureRectangle); } if (IsRecording || !captureRectangle.IsValid() || screenRecorder != null) { return; } Program.Settings.ScreenRecordRegion = captureRectangle; IsRecording = true; string path = ""; bool abortRequested = false; float duration = taskSettings.CaptureSettings.ScreenRecordFixedDuration ? taskSettings.CaptureSettings.ScreenRecordDuration : 0; recordForm = new ScreenRecordForm(captureRectangle, startMethod == ScreenRecordStartMethod.Region, duration); recordForm.StopRequested += StopRecording; recordForm.Show(); TaskEx.Run(() => { try { string filename = TaskHelpers.GetFilename(taskSettings, taskSettings.CaptureSettings.FFmpegOptions.Extension); path = TaskHelpers.CheckFilePath(taskSettings.CaptureFolder, filename, taskSettings); if (string.IsNullOrEmpty(path)) { abortRequested = true; } if (!abortRequested) { recordForm.ChangeState(ScreenRecordState.BeforeStart); if (taskSettings.CaptureSettings.ScreenRecordAutoStart) { int delay = (int)(taskSettings.CaptureSettings.ScreenRecordStartDelay * 1000); if (delay > 0) { recordForm.InvokeSafe(() => recordForm.StartCountdown(delay)); recordForm.RecordResetEvent.WaitOne(delay); } } else { recordForm.RecordResetEvent.WaitOne(); } if (recordForm.IsAbortRequested) { abortRequested = true; } if (!abortRequested) { ScreencastOptions options = new ScreencastOptions() { FFmpeg = taskSettings.CaptureSettings.FFmpegOptions, ScreenRecordFPS = taskSettings.CaptureSettings.ScreenRecordFPS, GIFFPS = taskSettings.CaptureSettings.GIFFPS, Duration = duration, OutputPath = path, CaptureArea = captureRectangle, DrawCursor = taskSettings.CaptureSettings.ScreenRecordShowCursor }; Screenshot screenshot = TaskHelpers.GetScreenshot(taskSettings); screenshot.CaptureCursor = taskSettings.CaptureSettings.ScreenRecordShowCursor; screenRecorder = new ScreenRecorder(ScreenRecordOutput.FFmpeg, options, screenshot, captureRectangle); screenRecorder.RecordingStarted += () => recordForm.ChangeState(ScreenRecordState.AfterRecordingStart); recordForm.ChangeState(ScreenRecordState.AfterStart); screenRecorder.StartRecording(); if (recordForm.IsAbortRequested) { abortRequested = true; } } } } catch (Exception e) { DebugHelper.WriteException(e); } try { if (!abortRequested && screenRecorder != null && File.Exists(path)) { recordForm.ChangeState(ScreenRecordState.AfterStop); string sourceFilePath = path; if (outputType == ScreenRecordOutput.GIF) { path = Path.Combine(taskSettings.CaptureFolder, TaskHelpers.GetFilename(taskSettings, "gif")); screenRecorder.FFmpegEncodeAsGIF(sourceFilePath, path, Program.ToolsFolder); } if (taskSettings.CaptureSettings.RunScreencastCLI) { VideoEncoder encoder = Program.Settings.VideoEncoders[taskSettings.CaptureSettings.VideoEncoderSelected]; path = Path.Combine(taskSettings.CaptureFolder, TaskHelpers.GetFilename(taskSettings, encoder.OutputExtension)); screenRecorder.EncodeUsingCommandLine(encoder, sourceFilePath, path); } } } finally { if (recordForm != null) { recordForm.InvokeSafe(() => { recordForm.Close(); recordForm.Dispose(); recordForm = null; }); } if (screenRecorder != null) { if ((outputType == ScreenRecordOutput.GIF || taskSettings.CaptureSettings.RunScreencastCLI) && !string.IsNullOrEmpty(screenRecorder.CachePath) && File.Exists(screenRecorder.CachePath)) { File.Delete(screenRecorder.CachePath); } screenRecorder.Dispose(); screenRecorder = null; if (abortRequested && !string.IsNullOrEmpty(path) && File.Exists(path)) { File.Delete(path); } } } }, () => { string customFileName; if (!abortRequested && !string.IsNullOrEmpty(path) && File.Exists(path) && TaskHelpers.ShowAfterCaptureForm(taskSettings, out customFileName, null, path)) { if (!string.IsNullOrEmpty(customFileName)) { string currentFilename = Path.GetFileNameWithoutExtension(path); string ext = Path.GetExtension(path); if (!currentFilename.Equals(customFileName, StringComparison.InvariantCultureIgnoreCase)) { path = Helpers.RenameFile(path, customFileName + ext); } } WorkerTask task = WorkerTask.CreateFileJobTask(path, taskSettings, customFileName); TaskManager.Start(task); } abortRequested = false; IsRecording = false; }); }
private void ZScreen_Load(object sender, EventArgs e) { Engine.zHandle = Handle; #region Window Size/Location if (Engine.ConfigApp.WindowLocation.IsEmpty) { Engine.ConfigApp.WindowLocation = Location; } if (Engine.ConfigApp.WindowSize.IsEmpty) { Engine.ConfigApp.WindowSize = Size; } if (Engine.ConfigApp.SaveFormSizePosition) { Rectangle screenRect = CaptureHelpers.GetScreenBounds(); screenRect.Inflate(-100, -100); if ( screenRect.IntersectsWith(new Rectangle(Engine.ConfigApp.WindowLocation, Engine.ConfigApp.WindowSize))) { Size = Engine.ConfigApp.WindowSize; Location = Engine.ConfigApp.WindowLocation; } } #endregion Window Size/Location #region Window Show/Hide bool bHideWindow = false; if (Engine.ConfigApp.ShowMainWindow) { if (Engine.ConfigApp.WindowState == FormWindowState.Maximized) { WindowState = FormWindowState.Maximized; } else { WindowState = FormWindowState.Normal; } ShowInTaskbar = Engine.ConfigApp.ShowInTaskbar; } else if (Engine.ConfigApp.ShowInTaskbar && Engine.ConfigApp.WindowButtonActionClose == WindowButtonAction.MinimizeToTaskbar) { WindowState = FormWindowState.Minimized; } else { bHideWindow = true; } if (Engine.ConfigApp.Windows7TaskbarIntegration && Engine.HasWindows7) { ZScreen_Windows7onlyTasks(); } if (bHideWindow) { Hide(); // this should happen after windows 7 taskbar integration } #endregion Window Show/Hide LoggerTimer timer = Engine.EngineLogger.StartTimer(new StackFrame().GetMethod().Name + " started"); ZScreen_Preconfig(); mDebug = new ZScreenDebugHelper(); mDebug.GetDebugInfo += debug_GetDebugInfo; SetToolTip(nudScreenshotDelay); new RichTextBoxMenu(rtbDebugLog, true); new RichTextBoxMenu(rtbStats, true); if (Engine.IsMultiInstance) { niTray.ShowBalloonTip(2000, Engine.GetProductName(), string.Format("Another instance of {0} is already running...", Application.ProductName), ToolTipIcon.Warning); niTray.BalloonTipClicked += niTray2_BalloonTipClicked; } timer.WriteLineTime(new StackFrame().GetMethod().Name + " finished"); Application.Idle += Application_Idle; }
private void btnFullscreen_Click(object sender, EventArgs e) { UpdateRegion(CaptureHelpers.GetScreenBounds()); }
public Bitmap CaptureFullscreen() { Rectangle bounds = CaptureHelpers.GetScreenBounds(); return(CaptureRectangle(bounds)); }
/// <summary> /// Crop shot or Selected Window captures /// </summary> /// <param name="myImage">Fullscreen image</param> /// <param name="windowMode">True = Selected window, False = Crop shot</param> public Crop(Image myImage, bool windowMode) { InitializeComponent(); selectedWindowMode = windowMode; bmpClean = new Bitmap(myImage); bmpBackground = new Bitmap(bmpClean); bmpRegion = new Bitmap(bmpClean); Bounds = CaptureHelpers.GetScreenBounds(); this.CursorPos = this.PointToClient(Cursor.Position); rectIntersect.Size = new Size(Bounds.Width - 1, Bounds.Height - 1); SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); CalculateBoundaryFromMousePosition(); timer.Tick += new EventHandler(TimerTick); windowCheck.Tick += new EventHandler(WindowCheckTick); if (selectedWindowMode) { captureObjects = Engine.ConfigUI.SelectedWindowCaptureObjects; myRectangle = new DynamicRectangle(CaptureType.SELECTED_WINDOW); WindowsListAdvanced wla = new WindowsListAdvanced(); wla.IgnoreWindows.Add(Handle); wla.IncludeChildWindows = captureObjects; windows = wla.GetWindowsRectangleList(); } else { myRectangle = new DynamicRectangle(CaptureType.CROP); if (Engine.ConfigUI.UseHardwareCursor) { Cursor = Cursors.Cross; } else { Cursor.Hide(); } } using (Graphics gBackground = Graphics.FromImage(bmpBackground)) using (Graphics gRegion = Graphics.FromImage(bmpRegion)) { gBackground.SmoothingMode = SmoothingMode.HighQuality; gRegion.SmoothingMode = SmoothingMode.HighQuality; if ((selectedWindowMode && Engine.ConfigUI.SelectedWindowRegionStyles == RegionStyles.REGION_TRANSPARENT) || (!selectedWindowMode && Engine.ConfigUI.CropRegionStyles == RegionStyles.REGION_TRANSPARENT)) { // If Region Transparent gRegion.FillRectangle(new SolidBrush(Color.FromArgb(Engine.ConfigUI.RegionTransparentValue, Color.White)), new Rectangle(0, 0, bmpRegion.Width, bmpRegion.Height)); } else if ((selectedWindowMode && Engine.ConfigUI.SelectedWindowRegionStyles == RegionStyles.REGION_BRIGHTNESS) || (!selectedWindowMode && Engine.ConfigUI.CropRegionStyles == RegionStyles.REGION_BRIGHTNESS)) { // If Region Brightness ImageAttributes imgattr = new ImageAttributes(); imgattr.SetColorMatrix(ColorMatrices.BrightnessFilter(Engine.ConfigUI.RegionBrightnessValue)); gRegion.DrawImage(bmpClean, new Rectangle(0, 0, bmpRegion.Width, bmpRegion.Height), 0, 0, bmpRegion.Width, bmpRegion.Height, GraphicsUnit.Pixel, imgattr); } else if ((selectedWindowMode && Engine.ConfigUI.SelectedWindowRegionStyles == RegionStyles.BACKGROUND_REGION_TRANSPARENT) || (!selectedWindowMode && Engine.ConfigUI.CropRegionStyles == RegionStyles.BACKGROUND_REGION_TRANSPARENT)) { // If Background Region Transparent gBackground.FillRectangle(new SolidBrush(Color.FromArgb(Engine.ConfigUI.BackgroundRegionTransparentValue, Color.White)), new Rectangle(0, 0, bmpBackground.Width, bmpBackground.Height)); } else if ((selectedWindowMode && Engine.ConfigUI.SelectedWindowRegionStyles == RegionStyles.BACKGROUND_REGION_BRIGHTNESS) || (!selectedWindowMode && Engine.ConfigUI.CropRegionStyles == RegionStyles.BACKGROUND_REGION_BRIGHTNESS)) { // If Background Region Brightness ImageAttributes imgattr = new ImageAttributes(); imgattr.SetColorMatrix(ColorMatrices.BrightnessFilter(Engine.ConfigUI.BackgroundRegionBrightnessValue)); gBackground.DrawImage(bmpClean, new Rectangle(0, 0, bmpBackground.Width, bmpBackground.Height), 0, 0, bmpBackground.Width, bmpBackground.Height, GraphicsUnit.Pixel, imgattr); } else if ((selectedWindowMode && Engine.ConfigUI.SelectedWindowRegionStyles == RegionStyles.BACKGROUND_REGION_GRAYSCALE) || (!selectedWindowMode && Engine.ConfigUI.CropRegionStyles == RegionStyles.BACKGROUND_REGION_GRAYSCALE)) { // If Background Region Grayscale ImageAttributes imgattr = new ImageAttributes(); imgattr.SetColorMatrix(ColorMatrices.GrayscaleFilter()); gBackground.DrawImage(bmpClean, new Rectangle(0, 0, bmpBackground.Width, bmpBackground.Height), 0, 0, bmpBackground.Width, bmpBackground.Height, GraphicsUnit.Pixel, imgattr); } } brushClean = new TextureBrush(bmpClean); brushBackground = new TextureBrush(bmpBackground); brushRegion = new TextureBrush(bmpRegion); }