본문 바로가기
프로그래밍

[C#] 초간단 캡쳐 함수

by 건우아빠유리남편 2011. 1. 11.
반응형
Graphics의 CopyFromScreen()함수가 주역

         //현재 폼 캡쳐
        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);

            g.CopyFromScreen(ptSource, new Point(0, 0), new Size(intBitmapWidth, intBitmapHeight));

            bitmap.Save(@"D:\Test.png", ImageFormat.Png);

            picCapImage.Image = bitmap;
            picCapImage.SizeMode = PictureBoxSizeMode.StretchImage;
        }


반응형

댓글