Search This Blog

Sunday, April 8, 2012

Capture and save active window including taskbar.

try
            {
                
                using (Bitmap imageBmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, Graphics.FromHwnd(IntPtr.Zero)))
                {
                
                    using (Graphics graphics = Graphics.FromImage(imageBmp))
                    {
                        graphics.CompositingQuality = CompositingQuality.HighQuality;
                        graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                        graphics.SmoothingMode = SmoothingMode.HighQuality;

                
                        graphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, imageBmp.Size, CopyPixelOperation.SourceCopy);
                        imageBmp.Save("d:\\temp.jpeg",ImageFormat.Jpeg);
                    }
                }
            }
            catch (Exception ex)
            {
                // log the exception

            }

No comments:

Post a Comment