简体   繁体   English

C#Printscreen | GDI +中发生了一般错误。

[英]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+. 但是当我按下按钮时,我收到以下错误:GDI +中发生了一般错误。

Any ideas? 有任何想法吗?

Thanks in advance. 提前致谢。

I bet it crashes calling Save , doesn't it? 我打赌它崩溃叫Save ,不是吗? :) :)

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 ;) 就像你的情况一样:我希望你不是试图将图像保存为桌面文件夹,因为它看起来像它;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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