位图保存无效参数

时间:2018-06-03 11:03:25

标签: c# bitmap save screenshot

我正在尝试创建一个截图工具,只是为了学习更多C#。

如果我想保存屏幕截图,我会收到错误“无效参数”。我错了什么?这是我的方法。

private void TakeSnapshot()
{
    string myDir = "C:\\Screenshots";

    try
    {
        Bitmap printscreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
        Graphics graphics = Graphics.FromImage(printscreen as Image);
        graphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, 0, 0, printscreen.Size);
        printscreen.Dispose();
        printscreen.Save(myDir + "Screenshot.png", ImageFormat.Png);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

1 个答案:

答案 0 :(得分:0)

有四个问题: