我正在尝试创建一个截图工具,只是为了学习更多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);
}
}
答案 0 :(得分:0)
有四个问题:
CopyFromScreen包含错误的参数。这就是结果全黑的原因。请在帮助中查找正确的参数:
https://msdn.microsoft.com/en-us/library/fw1kt6f9(v=vs.110).aspx