C# - Form Capture
2015. 2. 20. 20:53ㆍIT/C#
C#에서 폼화면을 캡쳐할려면, Graphics라는 클래스의 CopyFromScreen 매소드를 이용해야합니다.
먼저 폼 소스에서 아래의 매소드를 추가해주세요.
public void FormCapture(Size uFormSize, String uFileName)
{
Bitmap bitmap = new Bitmap(uFormSize.Width, uFormSize.Height);
Graphics g = Graphics.FromImage(bitmap);
g.CopyFromScreen(new Point(this.Bounds.X, this.Bounds.Y), new Point(0, 0), uFormSize);
bitmap.Save(uFileName, System.Drawing.Imaging.ImageFormat.Jpeg);
}
임의의 버튼을 생성하여, 버튼을 눌렀을 때 위에서 만든 FormCapture 메소드를 호출하면 폼 캡쳐가 됩니다.
private void button2_Click_1(object sender, EventArgs e)
{
Size sz = new Size(this.Bounds.Width, this.Bounds.Height);
FormCapture(sz, fileName);
}
전체 화면을 캡쳐할려면 위의 소스에서 조금만 수정하면 됩니다.
포인트를 0,0을 기준잡아줍니다. 참고로, 0,0은 왼쪽 상단입니다.
public void FormCapture(Size uFormSize, String uFileName)
{
Bitmap bitmap = new Bitmap(uFormSize.Width, uFormSize.Height);
Graphics g = Graphics.FromImage(bitmap);
g.CopyFromScreen(new Point(0, 0), new Point(0, 0), uFormSize);
bitmap.Save(uFileName, System.Drawing.Imaging.ImageFormat.Jpeg);
}
그리고 아래와 같이 주 디스플레이의 가로, 세로의 길이를 넣어주면 됩니다.
private void button2_Click_1(object sender, EventArgs e)
{
Size sz = new Size(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height);
FormCapture(sz, fileName);
}
'IT > C#' 카테고리의 다른 글
| [XAMARIN] App Life cycle과 환경 변수 (0) | 2019.05.25 |
|---|---|
| [XAMARIN] Button 이벤트 (0) | 2019.05.25 |
| [XAMARIN] 가변길이 문자열 화면에 표현하기 (0) | 2019.05.23 |
| [XAMARIN] 멀티뷰 - StatckLayout (0) | 2019.05.20 |
| [XAMARIN] Label 사용방법 (0) | 2019.05.19 |
| [XAMARIN] .net Standard에서 iOS, android, winPhone 구분하여 코딩하기 (0) | 2019.05.19 |
| Xamarin - 로또 번호 생성기 (0) | 2019.04.21 |
| C# - SaveFileDialog 사용방법 (2) | 2015.02.20 |