コード例 #1
0
        public Image GetScreenshot(Image fullscreenSS)
        {
            Rectangle rect = Rectangle.Round(path.GetBounds());

            rect.Location = CaptureHelpers.FixScreenCoordinates(rect.Location);

            Bitmap screenshot = new Bitmap(rect.Width, rect.Height);

            using (Graphics g = Graphics.FromImage(screenshot))
            {
                using (Matrix translateMatrix = new Matrix())
                {
                    rect.Location = CaptureHelpers.FixScreenCoordinates(rect.Location);
                    translateMatrix.Translate(-path.GetBounds().X, -path.GetBounds().Y);
                    path.Transform(translateMatrix);
                }

                g.IntersectClip(new Region(path));

                g.CompositingQuality = CompositingQuality.HighQuality;
                g.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                g.DrawImage(fullscreenSS, new Rectangle(0, 0, rect.Width, rect.Height), rect, GraphicsUnit.Pixel);
            }

            return(screenshot);
        }
コード例 #2
0
        public Surface(Image backgroundImage = null)
        {
            ScreenRectangle       = CaptureHelpers.GetScreenBounds();
            ScreenRectangle0Based = CaptureHelpers.FixScreenCoordinates(ScreenRectangle);

            InitializeComponent();

            SurfaceImage = backgroundImage;
            Prepare();

            DrawableObjects = new List <DrawableObject>();
            Config          = new SurfaceOptions();
            timer           = new Stopwatch();

            borderPen                 = new Pen(Color.DarkBlue);
            borderDotPen              = new Pen(Color.Black, 1);
            borderDotPen.DashPattern  = new float[] { 5, 5 };
            borderDotPen2             = new Pen(Color.White, 1);
            borderDotPen2.DashPattern = new float[] { 5, 5 };
            borderDotPen2.DashOffset  = 5;
            shadowBrush               = new SolidBrush(Color.FromArgb(75, Color.Black));
            lightBrush                = new SolidBrush(Color.FromArgb(10, Color.Black));
            nodeBackgroundBrush       = new SolidBrush(Color.White);
            textFont = new Font("Arial", 12, FontStyle.Bold);

            Shown            += new EventHandler(Surface_Shown);
            KeyUp            += new KeyEventHandler(Surface_KeyUp);
            MouseDoubleClick += new MouseEventHandler(Surface_MouseDoubleClick);
        }
コード例 #3
0
        public static Image CaptureRectangle(Rectangle rect)
        {
            if (RemoveOutsideScreenArea)
            {
                Rectangle bounds = CaptureHelpers.GetScreenBounds();
                rect = Rectangle.Intersect(bounds, rect);
            }

            Image img = CaptureRectangleNative(rect);

            if (DrawCursor)
            {
                Point cursorOffset = CaptureHelpers.FixScreenCoordinates(rect.Location);
                CaptureHelpers.DrawCursorToImage(img, cursorOffset);
            }

            return(img);
        }
コード例 #4
0
        private void DrawInfo(Graphics g)
        {
            string text = string.Format("FPS: {0}\nBounds: {1}", FPS, Bounds);

            SizeF textSize = g.MeasureString(text, textFont);

            int offset = 30;

            Rectangle primaryScreen = Screen.PrimaryScreen.Bounds;

            Point     position = CaptureHelpers.FixScreenCoordinates(new Point(primaryScreen.X + (int)(primaryScreen.Width / 2 - textSize.Width / 2), primaryScreen.Y + offset - 1));
            Rectangle rect     = new Rectangle(position, new Size((int)textSize.Width, (int)textSize.Height));

            if (rect.Contains(InputManager.MousePosition0Based))
            {
                position = CaptureHelpers.FixScreenCoordinates(new Point(primaryScreen.X + (int)(primaryScreen.Width / 2 - textSize.Width / 2),
                                                                         primaryScreen.Y + primaryScreen.Height - (int)textSize.Height - offset - 1));
            }

            CaptureHelpers.DrawTextWithOutline(g, text, position, textFont, Color.White, Color.Black);
        }
コード例 #5
0
        private void TimerTick(object sender, EventArgs e)
        {
            CalculateBoundaryFromMousePosition();

            if (Engine.ConfigUI.CropDynamicCrosshair)
            {
                forceCheck = true;
            }

            if (oldMousePos != mousePos || forceCheck)
            {
                oldMousePos = mousePos;
                forceCheck  = false;

                dragging = IsDragging(mousePos);

                if (selectedWindowMode && !dragging)
                {
                    foreach (Rectangle rect in windows)
                    {
                        if (rect.Contains(Cursor.Position))
                        {
                            CropRegion = CaptureHelpers.FixScreenCoordinates(rect);
                            break;
                        }
                    }
                }

                if (mouseDown && dragging)
                {
                    CropRegion = HelpersLib.GraphicsHelper.Core.GetRectangle(mousePos.X, mousePos.Y,
                                                                             mousePosOnClick.X - mousePos.X, mousePosOnClick.Y - mousePos.Y, Engine.ConfigUI.CropGridSize,
                                                                             Engine.ConfigUI.CropGridToggle, ref mousePos);
                    CropRegion = Rectangle.Intersect(CropRegion, rectIntersect);
                    mousePos   = mousePos.Intersect(rectIntersect);
                }

                Refresh();
            }
        }
コード例 #6
0
        private void CheckHover()
        {
            CurrentHoverArea = Rectangle.Empty;

            if (!ResizeManager.IsCursorOnNode() && !IsCreating && !IsMoving && !IsResizing)
            {
                Rectangle hoverArea = GetAreaIntersectWithMouse();

                if (!hoverArea.IsEmpty)
                {
                    CurrentHoverArea = hoverArea;
                }
                else if (WindowCaptureMode && Windows != null)
                {
                    hoverArea = Windows.FirstOrDefault(x => x.Contains(InputManager.MousePosition));

                    if (!hoverArea.IsEmpty)
                    {
                        hoverArea        = CaptureHelpers.FixScreenCoordinates(hoverArea);
                        CurrentHoverArea = Rectangle.Intersect(surface.ScreenRectangle0Based, hoverArea);
                    }
                }
            }
        }
コード例 #7
0
 public void Update()
 {
     Buttons           = Control.MouseButtons;
     Position          = Control.MousePosition;
     ZeroBasedPosition = CaptureHelpers.FixScreenCoordinates(Position);
 }
コード例 #8
0
        public static Image CaptureWindowTransparent(IntPtr handle)
        {
            if (handle.ToInt32() > 0)
            {
                Rectangle rect = CaptureHelpers.GetWindowRectangle(handle);
                Bitmap    whiteBackground = null, blackBackground = null, whiteBackground2 = null;
                MyCursor  cursor        = null;
                bool      isTransparent = false;

                try
                {
                    if (DrawCursor)
                    {
                        cursor = NativeMethods.CaptureCursor();
                    }

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

                        if (CaptureShadow && !NativeMethods.IsZoomed(handle) && NativeMethods.IsDWMEnabled())
                        {
                            const int offset = 20;

                            rect.Inflate(offset, offset);
                            rect.Intersect(CaptureHelpers.GetScreenBounds());
                        }

                        NativeMethods.ShowWindow(form.Handle, (int)WindowShowStyle.ShowNormalNoActivate);

                        if (!NativeMethods.SetWindowPos(form.Handle, handle, rect.X, rect.Y, rect.Width, rect.Height, NativeMethods.SWP_NOACTIVATE))
                        {
                            form.Close();
                            DebugHelper.WriteLine("Transparent capture failed. Reason: SetWindowPos fail.");
                            return(CaptureWindow(handle));
                        }

                        Thread.Sleep(10);
                        Application.DoEvents();

                        whiteBackground = (Bitmap)Screenshot.CaptureRectangleNative(rect);

                        form.BackColor = Color.Black;
                        Application.DoEvents();

                        blackBackground = (Bitmap)Screenshot.CaptureRectangleNative(rect);

                        form.BackColor = Color.White;
                        Application.DoEvents();

                        whiteBackground2 = (Bitmap)Screenshot.CaptureRectangleNative(rect);

                        form.Close();
                    }

                    Bitmap transparentImage;

                    if (IsImagesEqual(whiteBackground, whiteBackground2))
                    {
                        transparentImage = CreateTransparentImage(whiteBackground, blackBackground);
                        isTransparent    = true;
                    }
                    else
                    {
                        DebugHelper.WriteLine("Transparent capture failed. Reason: Images not equal.");
                        transparentImage = whiteBackground2;
                    }

                    if (cursor != null)
                    {
                        Point cursorOffset = CaptureHelpers.FixScreenCoordinates(rect.Location);
                        CaptureHelpers.DrawCursorToImage(cursor, transparentImage, cursorOffset);
                    }

                    if (isTransparent)
                    {
                        transparentImage = TrimTransparent(transparentImage);

                        if (!CaptureShadow)
                        {
                            TrimShadow(transparentImage);
                        }
                    }

                    return(transparentImage);
                }
                finally
                {
                    if (whiteBackground != null)
                    {
                        whiteBackground.Dispose();
                    }
                    if (blackBackground != null)
                    {
                        blackBackground.Dispose();
                    }
                    if (isTransparent && whiteBackground2 != null)
                    {
                        whiteBackground2.Dispose();
                    }
                    if (cursor != null)
                    {
                        cursor.Dispose();
                    }
                }
            }

            return(null);
        }