保存屏幕截图时

时间:2016-09-06 11:07:39

标签: c# asp.net bitmap

我正在尝试使用代码捕获屏幕截图:

Bitmap bitmap = new Bitmap (Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);

    Graphics graphics = Graphics.FromImage(bitmap as System.Drawing.Image);
    graphics.CopyFromScreen(25, 25, 25, 25, bitmap.Size);

    bitmap.Save("C:\\Users\\Mayank\\Desktop\\Screenshot\\", ImageFormat.Bmp);

最后一行导致以下错误: GDI +中出现了一般错误

请帮助:)

2 个答案:

答案 0 :(得分:0)

int width=800;int height=480;
using (Bitmap bmpScreenCapture = new Bitmap(width,height))
{
using (Graphics g = Graphics.FromImage(bmpScreenCapture))
{
g.CopyFromScreen(0,0,0, 0,bmpScreenCapture.Size,CopyPixelOperation.SourceCopy);bmpScreenCapture.Save("test.png");
}
}

答案 1 :(得分:-1)

我自己解决了这个问题。问题在于我提供文件路径和名称的方式。使用以下代码解决了它:

bmpScreenCapture.Save(@"C:\Users\Mayank\Desktop\Screenshot\TestFile.bmp");
相关问题