728x90
private void button1_Click(object sender, EventArgs e)
{
ScreenCapture(this.Width, this.Height, this.Location);
}
//현재 폼 캡쳐
private void btnCapture_Click(object sender, EventArgs e)
{
ScreenCapture(this.Width, this.Height, this.Location);
}
//Full Screen 캡쳐
private void btnFullScreenCapture_Click(object sender, EventArgs e)
{
ScreenCapture(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height, new Point(0, 0));
}
//캡쳐 함수
private void ScreenCapture(int intBitmapWidth, int intBitmapHeight, Point ptSource)
{
Bitmap bitmap = new Bitmap(intBitmapWidth, intBitmapHeight);
Graphics g = Graphics.FromImage(bitmap);
//바탕 화면 경로
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\Test";
g.CopyFromScreen(ptSource, new Point(0, 0), new Size(intBitmapWidth, intBitmapHeight));
//폴더 생성
DirectoryInfo di = new DirectoryInfo(desktopPath);
if (di.Exists == false) di.Create();
//이미지 저장 경로
bitmap.Save(@desktopPath + @"\test.png", ImageFormat.Png);
//폼 픽쳐박스에 캠쳐 이미지 표시
pictureBox1.Image = bitmap;
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
}
출처: najsulman.tistory.com/m/519, louiey.tistory.com/entry/c-%EC%8A%A4%ED%81%AC%EB%A6%B0-%EC%BA%A1%EC%B3%90%ED%95%98%EA%B8%B0
728x90
'C#' 카테고리의 다른 글
C# / Text to Speech(TTS) 사용, 음성 출력 하기 (0) | 2021.05.18 |
---|---|
C# / switch case range, switch case 범위 연산자 (0) | 2021.05.18 |
C# / 텍스트 박스 전부 비우기 (0) | 2021.04.12 |
C# / concurrentdictionary copy, 딕셔러니 복사 (0) | 2021.04.09 |
C# / 메소드, 함수 종료 하기 (0) | 2021.04.08 |