1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【C#】画面のスクリーンショット

Last updated at Posted at 2025-10-26

現在の画面の内容を保存したいときなどに使える、画面全体のスクリーンショットを撮って保存するコードを記載。

ソースコード

public static void CaptureScreen(string savePath)
{
    try
    {
        // スクリーンのサイズを取得
        Rectangle screenBounds = Screen.PrimaryScreen.Bounds;

        // Bitmapを作成
        using (Bitmap bmp = new Bitmap(screenBounds.Width, screenBounds.Height))
        {
            // Graphicsを使って画面をコピー
            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.CopyFromScreen(screenBounds.Left, screenBounds.Top, 0, 0, screenBounds.Size);
            }

            // PNG形式で保存
            bmp.Save(savePath, ImageFormat.Png);
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine($"スクリーンショット取得に失敗しました: {ex.Message}");
    }
}

株式会社ONE WEDGE

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?