Rooler.ScreenShot.Capture C# (CSharp) Method

Capture() private method

private Capture ( IntRect bounds ) : void
bounds IntRect
return void
        private void Capture(IntRect bounds)
        {
            this.bounds = bounds;

            BitmapSource bitmap = null;

            using (NativeMethods.DC hdcScreen = NativeMethods.CreateDC("Display", null, null, IntPtr.Zero)) {
                using (NativeMethods.DC hdcDest = hdcScreen.CreateCompatibleDC()) {
                    using (NativeMethods.GdiObject hBitmap = hdcScreen.CreateCompatibleBitmap(bounds.Width, bounds.Height)) {
                        NativeMethods.GdiObject oldBitmap = hdcDest.SelectObject(hBitmap);
                        hdcDest.BitBlt(0, 0, bounds.Width, bounds.Height, hdcScreen, bounds.Left, bounds.Top, 0xcc0020);

                        bitmap = Imaging.CreateBitmapSourceFromHBitmap(hBitmap.IntPtr, IntPtr.Zero, new Int32Rect(0, 0, bounds.Width, bounds.Height), null);
                        hdcDest.SelectObject(oldBitmap);
                    }
                }
            }

            //IntPtr hdcScreen = NativeMethods.CreateDC("Display", null, null, IntPtr.Zero);
            //if (hdcScreen != IntPtr.Zero) {
            //    IntPtr hdcDest = NativeMethods.CreateCompatibleDC(hdcScreen);
            //    if (hdcDest != IntPtr.Zero) {
            //        IntPtr hBitmap = NativeMethods.CreateCompatibleBitmap(hdcScreen, bounds.Width, bounds.Height);
            //        if (hBitmap != IntPtr.Zero) {
            //            IntPtr oldBitmap = NativeMethods.SelectObject(hdcDest, hBitmap);
            //            NativeMethods.BitBlt(hdcDest, 0, 0, bounds.Width, bounds.Height, hdcScreen, bounds.X, bounds.Y, 0xcc0020);

            //            bitmap = Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, new Int32Rect(0, 0, bounds.Width, bounds.Height), null);
            //            NativeMethods.SelectObject(hdcDest, oldBitmap);
            //            NativeMethods.DeleteObject(hBitmap);
            //        }
            //        NativeMethods.DeleteDC(hdcDest);
            //    }
            //    NativeMethods.DeleteDC(hdcScreen);
            //}

            if (bitmap != null) {
                this.Init(bitmap);
            }
        }