I'm trying to take a screenshot of the screen in C# Windows Forms. Code (from https://www.c-sharpcorner.com/UploadFile/2d2d83/how-to-capture-a-screen-using-C-Sharp/):
Bitmap captureBitmap = new Bitmap(1600, 900, PixelFormat.Format32bppArgb);
Rectangle captureRectangle = Screen.AllScreens[0].Bounds;
Graphics captureGraphics = Graphics.FromImage(captureBitmap);
captureGraphics.CopyFromScreen(captureRectangle.Left, captureRectangle.Top, 0, 0, captureRectangle.Size);
captureBitmap.Save(@"C:\Screenshot.jpg", ImageFormat.Jpeg);
It throws this error: A generic error occured in GDI+ (in captureBitmap.Save). What can I do? I tried using captureBitmap.Dispose() but it still doesn't work.