윈도우 폼을 이용하여 화면을 캡쳐하는 프로그램을 만들어 보겠습니다.
System.Drawing에서 제공되는 동작들을 통해 쉽게 결과를 얻을 수 있습니다.
using System;
using System.Windows.Forms;
using System.Drawing.Imaging; //PixelFormat, ImageFormat
using System.Drawing; //Bitmap, Graphics
using System.IO; //Path
namespace WindowsFormsApp
{
public partial class Form1 : Form
{
private void ScreenShot(int width, int height, int x, int y)
{
Bitmap bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
Graphics graphics = Graphics.FromImage(bitmap);
graphics.CopyFromScreen(x, y, 0, 0, bitmap.Size);
//현재 프로젝트 위치에 저장됩니다.
string path = Environment.CurrentDirectory;
string fileName = "image.png";
//MessageBox.Show(Path.Combine(path + fileName));
bitmap.Save(Path.Combine(path, fileName), ImageFormat.Png);
}
public Form1()
{
InitializeComponent();
//Screen.PrimaryScreen : 1번 모니터
//WorkingArea : 작업표시줄 제외한 범위
ScreenShot(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height, 0, 0);
}
}
}

'C# > Windows Form' 카테고리의 다른 글
[C# Windows Form] FormBorderStyle = None 인 경우 모니터 위치에 맞게 최대화 시키기 (0) | 2022.07.26 |
---|---|
[C# Windows Form] ListView 기본 사용법 (1) 컬럼 및 아이템 (0) | 2022.06.15 |
[C# Windows Form] 이미지 회전 시키기 (Image, Graphics) (0) | 2022.05.05 |
[C# Windows Form] 마우스 매크로 만들기 (0) | 2022.04.28 |
[C# Windows Form] 키보드 후킹 (0) | 2022.03.01 |