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

+ Recent posts