본문으로 바로가기

Window Screen Capture

category Development/C# 2012. 8. 23. 10:26

윈도우 화면을 캡쳐.

        private void WindowCapture(Window win)
        {
            RenderTargetBitmap bmp = new RenderTargetBitmap((int)win.Width, (int)win.Height, 96, 96, PixelFormats.Pbgra32);
            bmp.Render(win);

            string PicPath = "c:\\Screenshot\\";
            if (!Directory.Exists(PicPath))
                Directory.CreateDirectory(PicPath);

            BitmapEncoder encoder = new PngBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(bmp));

            string filePath = PicPath + string.Format("{0:MMddyyyyhhmmss}.png", DateTime.Now);
            using (Stream stream = File.Create(filePath))
            {
                encoder.Save(stream);
            }
        }