The code below works here and there. Sometimes it save the image just fine, and other times it doesn't. The image is being save locally and the folder has the correct permissions.
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
}
bitmap.Save("test.png", ImageFormat.Png);
}
Rectangle newbounds = Bounds;
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);
}
bitmap.Save(picLocation, ImageFormat.Png);
}
Here is the error that I am getting:
Can someone please tell me what I am doing wrong?