c# Take a screenshot of specific area [closed]

2019-06-04 00:23发布

问题:

I know there are many questions like this but none of their answers are working for me or just I can't do it correctly, anyway if it's possible please give me a simple code!

I know the location of the green dot and I want to construct a rectangle based on this location.

Example:

And most important how to take a screenshot of this area?

I don't know how to change this code to work for my case.

private Bitmap Screenshot()
    {
        Bitmap bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);

        Graphics g = Graphics.FromImage(bmpScreenshot);

        g.CopyFromScreen(0, 0, 0, 0, Screen.PrimaryScreen.Bounds.Size);

        return bmpScreenshot;
    }

回答1:

Merging the documentation on MSDN and your problem:

g.CopyFromScreen(center.X - 36, center.Y - 30, 0, 0, new Size(36 * 2, 30 * 2));