Programming/Language

[C#] 스크린 캡처

appHunter 2016. 4. 4. 16:39

1. Win32 api이용, Active Window의 handle을 찾음.
        [DllImport("user32.dll")]
        public static extern IntPtr GetForegroundWindow();

2. Win32 api이용, window handle값으로, 창 정보를 읽어옴.
        [DllImport("user32.dll")]
        public static extern IntPtr GetWindowRect(IntPtr hWnd, ref RECT rect);

3. screen에서 capture
      Graphics 의  CopyFromScreen 메서드 이용하여 Bitmap으로 capture
     Image or Bitmap 의 Save메서드를 이용하여, 파일로 저장
     Bimap b = new Bitmap(rect.Width, rect.Height);
     Graphics g = Graphics.FromImage(b);
     g.CopyFromScreen(startPoint, Point.Empty, rect.Size);
 
    b.Save(sFile)....
 
1,2,3순으로 하면 간단히 캡쳐 저장됩니다. 글에 오타 있을테니 차근차근 해보세요.
CopyFormScreen의 desctop전체 크기넣으면 전체화면 캡쳐가 됩니다.

 

출처 : 훈스닷넷