如何使用Windows API捕获屏幕和鼠标指针?

问题描述 投票:16回答:2

我正在使用以下代码捕获位图中的屏幕。屏幕被捕获,但我无法在屏幕上显示鼠标指针。您能否建议一些替代方法,以便捕获鼠标?

    private Bitmap CaptureScreen()
    {
        // Size size is how big an area to capture
        // pointOrigin is the upper left corner of the area to capture
        int width = Screen.PrimaryScreen.Bounds.X + Screen.PrimaryScreen.Bounds.Width;
        int height = Screen.PrimaryScreen.Bounds.Y + Screen.PrimaryScreen.Bounds.Height;
        Size size = new Size(width, height);
        Point pointOfOrigin = new Point(0, 0);

        Bitmap bitmap = new Bitmap(size.Width, size.Height);
        {
            using (Graphics graphics = Graphics.FromImage(bitmap))
            {
                graphics.CopyFromScreen(pointOfOrigin, new Point(0, 0), size);
            }
            return bitmap;
        }
    }
c# .net graphics
2个回答
© www.soinside.com 2019 - 2024. All rights reserved.