Share via

saving a bitmap

Tanne 41 Reputation points
2021-02-16T19:06:49.983+00:00

I am having trouble saving a bitmap to my hardrive, this is the code im using:
{
class Program
{

    static void Main(string[] args)
    {
        using (Bitmap screenshot = new Bitmap(53, 21))
        {
            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");

        }
    }
}

}

when I run it i get an error on the screenshot.save line it puts a break there and says System.Runtime.InteropServices.ExternalException: 'A generic error occurred in GDI+.'
Any ideas why?

Developer technologies | Visual Studio | Other
Developer technologies | Visual Studio | Other

A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.

0 comments No comments

Answer accepted by question author

Viorel 127K Reputation points
2021-02-16T19:27:16.633+00:00

Try saving to some less-protected folder or disk.

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

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