public static async Task <Screenshot?> CaptureSelection(HSSettings settingsContext)
        {
            if (settingsContext == null)
            {
                throw new ArgumentNullException(nameof(settingsContext));
            }

            Debug.Assert(!SelectionSemaphore.IsInAreaSelection);

            if (SelectionSemaphore.IsInAreaSelection)
            {
                return(null);
            }

            using var prio = new ProcessPriorityRequest();
            var(screen, cursorPosition) = ScreenshotCreator.CaptureScreenshot(SystemInformation.VirtualScreen, settingsContext.CaptureCursor);
            using var selector          = AreaSelector.Create(screen, true, settingsContext);

            var(selectedArea, _) = await selector.PromptSelectionAsync().ConfigureAwait(true);

            Debug.Assert(selectedArea.Width > 0);
            Debug.Assert(selectedArea.Height > 0);

            var selectedImage = new Bitmap(selectedArea.Width, selectedArea.Height);

            var cursorPositionOnSelectedImage = cursorPosition == null
                ? null
                : cursorPosition with {
                OnImage = new Point(cursorPosition.OnImage.X - selectedArea.X, cursorPosition.OnImage.Y - selectedArea.Y)
            };

            using var g = Graphics.FromImage(selectedImage);

            g.DrawImage(screen, new Rectangle(0, 0, selectedArea.Width, selectedArea.Height), selectedArea, GraphicsUnit.Pixel);

            return(Screenshot.FromImage(selectedImage, cursorPosition, ScreenshotSource.Selected));
        }
    }
Beispiel #2
0
 public static Screenshot CaptureFullScreen(HSSettings settingsContext)
 {
     using var prio = new ProcessPriorityRequest();
     var(screen, cursorPosition) = ScreenshotCreator.CaptureScreenshot(SystemInformation.VirtualScreen, settingsContext.CaptureCursor);
     return(Screenshot.FromImage(screen, cursorPosition, ScreenshotSource.Fullscreen));
 }