以下のコードはあちこちで機能します。画像がうまく保存される場合もあれば、保存されない場合もあります。画像はローカルに保存されており、フォルダーには適切な権限があります。
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);
}
これが私が得ているエラーです:
誰かが私が間違っていることを教えてもらえますか?