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?

Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
935 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 81,461 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