Example #1
0
        private void InitializeComponent()
        {
            this.SuspendLayout();
            this.Bounds           = GraphicsMgr.GetScreenBounds();
            this.CausesValidation = false;
            this.ControlBox       = true;
            this.Cursor           = Cursors.Cross;
            this.DoubleBuffered   = true;
            this.FormBorderStyle  = FormBorderStyle.None;
            this.KeyPreview       = true;
            this.MaximizeBox      = false;
            this.MinimizeBox      = false;
            this.Name             = "Crop";
            this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
            this.ShowIcon = false;
#if !DEBUG
            this.TopMost = true;
#endif
            this.ShowInTaskbar = false;
            this.ResumeLayout(false);

            this.KeyDown += new KeyEventHandler(Crop2_KeyDown);

            this.DoubleClick += new EventHandler(Crop_MouseDobuleClick);
        }
Example #2
0
        public static Image CaptureScreen(bool showCursor)
        {
            Image img = CaptureRectangle(GraphicsMgr.GetScreenBounds());

            if (showCursor)
            {
                DrawCursor(img);
            }
            return(img);
        }
        /// <summary>
        /// Captures a screenshot of a window using Windows GDI. Captures transparency.
        /// </summary>
        /// <param name="handle">handle of the window to capture</param>
        /// <returns>the captured window image</returns>
        private static Image CaptureWindowWithTransparencyGDI(IntPtr handle, Rectangle windowRect)
        {
            Image  windowImage = null;
            Bitmap whiteBGImage = null, blackBGImage = null, white2BGImage = null;

            try
            {
                using (new Freeze(handle))
                    using (Form form = new Form())
                    {
                        form.BackColor       = Color.White;
                        form.FormBorderStyle = FormBorderStyle.None;
                        form.ShowInTaskbar   = false;

                        int offset = Engine.conf.ActiveWindowIncludeShadows && !NativeMethods.IsWindowMaximized(handle) ? 20 : 0;

                        windowRect = windowRect.AddMargin(offset);
                        windowRect.Intersect(GraphicsMgr.GetScreenBounds());

                        NativeMethods.ShowWindow(form.Handle, (int)NativeMethods.WindowShowStyle.ShowNormalNoActivate);
                        NativeMethods.SetWindowPos(form.Handle, handle, windowRect.X, windowRect.Y, windowRect.Width, windowRect.Height, NativeMethods.SWP_NOACTIVATE);
                        Application.DoEvents();
                        whiteBGImage = (Bitmap)CaptureRectangle(NativeMethods.GetDesktopWindow(), windowRect);

                        form.BackColor = Color.Black;
                        Application.DoEvents();
                        blackBGImage = (Bitmap)CaptureRectangle(NativeMethods.GetDesktopWindow(), windowRect);

                        if (!Engine.conf.ActiveWindowGDIFreezeWindow)
                        {
                            form.BackColor = Color.White;
                            Application.DoEvents();
                            white2BGImage = (Bitmap)CaptureRectangle(NativeMethods.GetDesktopWindow(), windowRect);
                        }
                    }

                if (Engine.conf.ActiveWindowGDIFreezeWindow || whiteBGImage.AreBitmapsEqual(white2BGImage))
                {
                    windowImage = GraphicsMgr.ComputeOriginal(whiteBGImage, blackBGImage);
                }
                else
                {
                    windowImage = (Image)whiteBGImage.Clone();
                }
            }
            finally
            {
                if (whiteBGImage != null)
                {
                    whiteBGImage.Dispose();
                }
                if (blackBGImage != null)
                {
                    blackBGImage.Dispose();
                }
                if (white2BGImage != null)
                {
                    white2BGImage.Dispose();
                }
            }

            if (windowImage != null)
            {
                Rectangle windowRectCropped = GraphicsMgr.GetCroppedArea((Bitmap)windowImage);
                windowImage = GraphicsMgr.CropImage(windowImage, windowRectCropped);

                if (Engine.conf.ShowCursor)
                {
                    windowRect.X += windowRectCropped.X;
                    windowRect.Y += windowRectCropped.Y;
                    DrawCursor(windowImage, windowRect.Location);
                }

                if (Engine.conf.ActiveWindowShowCheckers)
                {
                    windowImage = ImageEffects.DrawCheckers(windowImage);
                }
            }

            return(windowImage);
        }