保存截图时的问题

本文关键字:问题 保存 | 更新日期: 2023-09-27 18:06:04

我正在尝试以下代码捕获屏幕截图:

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+

出现一般性错误

请帮忙:)

保存截图时的问题

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");
}
}

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

bmpScreenCapture.Save(@"C:'Users'Mayank'Desktop'Screenshot'TestFile.bmp");