graphics screen capture makes a black image

Tanne 41 Reputation points
2021-02-18T04:03:03.107+00:00

When I Run this code I get a black png:

class Program
{

    static void Main(string[] args)
    {
        Console.ReadLine();

        using (Bitmap screenshot = new Bitmap(53, 21))
        {
            System.IO.File.Delete("C:\\test.png");

            using (Graphics image = Graphics.FromImage(screenshot))
            {
                image.CopyFromScreen(new Point(81, 160), new Point(134, 181), new Size(53, 21));
            }
            screenshot.Save("C:\\test.png");

            screenshot.Dispose();




        }

    }
}

any ideas why?

Developer technologies | Visual Studio | Debugging
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 90,686 Reputation points
    2021-02-18T04:17:40.297+00:00

    new Point(134, 181) is the destination, so it is out of bounds

    replace it by new Point(0, 0)

    (and don't use Dispose when you use using...)


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.