简体   繁体   中英

C# Printscreen | A generic error occurred in GDI+.

So I have this form where if the user presses a button, this method gets executed:

//Takes a screenshot of the screen to send it with the email
    private void screenshot()
    {
        Bitmap printscreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);

        Graphics graphics = Graphics.FromImage(printscreen as Image);

        graphics.CopyFromScreen(0,0,0,0, printscreen.Size);

        printscreen.Save(@"C:\Users\*******\Desktop", ImageFormat.Jpeg);
    }

But when I press the button I get the following error: A generic error occurred in GDI+.

Any ideas?

Thanks in advance.

I bet it crashes calling Save , doesn't it? :)

Make absolutely sure it is possible to write to that file! Like in your case: I hope you're not trying to save the image as your desktop folder, because it kind of looks like it ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM