示例#1
0
        public static Bitmap CopyScreen(bool hideCursor)
        {
            var CurrScreen = GetScreenBoundaries();

            Console.WriteLine("Post Scaling: - Top: {0}, Left: {1}, Width: {2}, Height: {3}", CurrScreen.Y, CurrScreen.X, CurrScreen.Width, CurrScreen.Height);

            var w = BitBltCopy(CurrScreen);
            var g = Graphics.FromImage(w);

            if (!hideCursor)
            {
                try
                {
                    int x = 0, y = 0;
                    var cursor = WinApi.CaptureCursor(ref x, ref y);
                    //calculate x & y's real position relative to the form.
                    //which is (-left)+x | (-top)+y
                    x = x + -CurrScreen.Left;
                    y = y + -CurrScreen.Top;
                    g.DrawImage(cursor, new Point(x, y));
                    cursor.Dispose();
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error while capturing the cursor: {ex}");
                }
            }

            g.Flush();
            g.Dispose();
            return(w);
        }