Online screen snapshot12/28/2023 ![]() ![]() I extended it a bit to allow a little more flexibility on save format, as well as the ability to save by hWnd. G.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size) Using (var g = Graphics.FromImage(result)) GetWindowRect(foregroundWindowsHandle, ref rect) īounds = new Rectangle(rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top) ĬursorPosition = new Point( - rect.Left, - rect.Top) Var foregroundWindowsHandle = GetForegroundWindow() If (screenCaptureMode = enmScreenCaptureMode.Screen) Public Bitmap Capture(enmScreenCaptureMode screenCaptureMode = enmScreenCaptureMode.Window) I suggest next solution for capturing any current active window (not only our C# application) or entire screen with cursor position determination relative to left-top corner of window or screen respectively: public enum enmScreenCaptureMode How to capture the active window: var image = ImageFormat.Jpeg) How to capture the whole screen: var image = ImageFormat.Jpeg) Graphics.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size) Using (var graphics = Graphics.FromImage(result)) Var result = new Bitmap(bounds.Width, bounds.Height) ![]() Var bounds = new Rectangle(rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top) Public static Bitmap CaptureWindow(IntPtr handle) ![]() Return CaptureWindow(GetForegroundWindow()) Public static Bitmap CaptureActiveWindow() Return CaptureWindow(GetDesktopWindow()) Private static extern IntPtr GetWindowRect(IntPtr hWnd, ref Rect rect) Public static extern IntPtr GetDesktopWindow() Private static extern IntPtr GetForegroundWindow() Here is a snippet to capture either the desktop or the active window. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |