이전 글의 구글클라우드비전API를 사용하다보니 할때마다 이미지를 캡쳐하고 잘라내야해서

그게 귀찮아서 직접 스크린 캡쳐프로그램을 만들어봤다.


물론 winAPI를 공부하지는 않았어서 구글링하면서 하나하나 가져와서 커스터마이즈했다..


일단 기본 캡쳐방법이다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
private void capture_button_Click(object sender, RoutedEventArgs e)
{
    // 듀얼 모니터까지 다합쳐서 길이
    //double screenLeft = SystemParameters.VirtualScreenLeft;
    //double screenTop = SystemParameters.VirtualScreenTop;
    //double screenWidth = SystemParameters.VirtualScreenWidth;
    //double screenHeight = SystemParameters.VirtualScreenHeight;
 
    // 현재 모니터의 크기
    //double screenWidth = SystemParameters.WorkArea.Width;
    //double screenHeight = SystemParameters.WorkArea.Height;
    double screenWidth = CropCapture_Window.ActualWidth;
    double screenHeight = CropCapture_Window.ActualHeight;
 
    // 시작점의 위치를 잡는다. (0,0)부터의 위치를 받아와서 두께만큼 더해줌.
    var startPoint = CropCapture_Window.PointToScreen(new System.Windows.Point(00));
    startPoint.X += borderthickness;
    startPoint.Y += borderthickness;
 
    // Bitmap을 캡쳐창의 크기만큼 생성함(테두리 두께만큼 제외. 테두리가 찍히는것을 방지하기위해)
    using (Bitmap bmp = new Bitmap((int)(screenWidth - borderthickness * 2),
        (int)(screenHeight - borderthickness * 2)))
    {
        using (Graphics g = Graphics.FromImage(bmp))
        {
            String filename = "CropScreenCapture-" + DateTime.Now.ToString("yyyyMMdd-HHmmss"+ ".png";
            Opacity = .0;
            //g.CopyFromScreen((int)screenLeft, (int)screenTop, 0, 0, bmp.Size);
            // 시작점부터 bitmap의 (0,0)부터 그리기 시작함.
            g.CopyFromScreen((int)startPoint.X, (int)startPoint.Y, 00, bmp.Size);
            bmp.Save("D:\\" + filename);
            Opacity = 1;
 
            MessageBox.Show("캡쳐가 저장되었습니다.\n" + "D:\\" + filename);
        }
    }
}
cs

new Bitmap으로 크기를 잡아서 Bitmap을 생성하고. Graphic.CopyFromScreen을 이용하면 스크린화면을 복사할수 있다.

전체화면 캡쳐, 크롭 캡쳐는 비트맵의 사이즈와 시작점만 잘잡아주면 된다.


그 외 끌어서 창맞춤 기능과 UI디자인은 오픈소스 프로그램인 ScreenToGif를 많이 참고했다.

https://github.com/NickeManarin/ScreenToGif


--------------------------------------------------------------------------------------


실행 결과 

캡쳐한 이미지


이것도 마찬가지로 풀코드는 깃헙을 참고

https://github.com/kiwiade/GoogleVisionAPI-Capture

Posted by misty_
,