Ejemplo n.º 1
0
        public Image GetResultImage()
        {
            if (Mode == RegionCaptureMode.Editor)
            {
                foreach (BaseShape shape in ShapeManager.Shapes)
                {
                    shape.Move(-ImageRectangle.X, -ImageRectangle.Y);
                }

                Image img = GetOutputImage();

                foreach (BaseShape shape in ShapeManager.Shapes)
                {
                    shape.Move(ImageRectangle.X, ImageRectangle.Y);
                }

                return(img);
            }
            else if (Result == RegionResult.Region)
            {
                using (Image img = GetOutputImage())
                {
                    return(RegionCaptureTasks.ApplyRegionPathToImage(img, regionFillPath));
                }
            }
            else if (Result == RegionResult.Fullscreen)
            {
                return(GetOutputImage());
            }
            else if (Result == RegionResult.Monitor)
            {
                Screen[] screens = Screen.AllScreens;

                if (MonitorIndex < screens.Length)
                {
                    Screen    screen     = screens[MonitorIndex];
                    Rectangle screenRect = CaptureHelpers.ScreenToClient(screen.Bounds);

                    using (Image img = GetOutputImage())
                    {
                        return(ImageHelpers.CropImage(img, screenRect));
                    }
                }
            }
            else if (Result == RegionResult.ActiveMonitor)
            {
                Rectangle activeScreenRect = CaptureHelpers.GetActiveScreenBounds0Based();

                using (Image img = GetOutputImage())
                {
                    return(ImageHelpers.CropImage(img, activeScreenRect));
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        private void DrawTopCenterTip(Graphics g, string text, double opacity = 1)
        {
            Size      textSize      = g.MeasureString(text, infoFontMedium).ToSize();
            int       offset        = 10;
            int       padding       = 3;
            int       rectWidth     = textSize.Width + padding * 2;
            int       rectHeight    = textSize.Height + padding * 2;
            Rectangle screenBounds  = CaptureHelpers.GetActiveScreenBounds0Based();
            Rectangle textRectangle = new Rectangle(screenBounds.X + (screenBounds.Width / 2) - (rectWidth / 2), screenBounds.Y + offset, rectWidth, rectHeight);

            using (Brush backgroundBrush = new SolidBrush(Color.FromArgb((int)(opacity * 75), Color.Black)))
                using (Pen outerBorderPen = new Pen(Color.FromArgb((int)(opacity * 50), Color.White)))
                    using (Pen innerBorderPen = new Pen(Color.FromArgb((int)(opacity * 150), Color.Black)))
                        using (Brush textBrush = new SolidBrush(Color.FromArgb((int)(opacity * 255), Color.White)))
                            using (Brush textShadowBrush = new SolidBrush(Color.FromArgb((int)(opacity * 255), Color.Black)))
                            {
                                DrawInfoText(g, text, textRectangle, infoFontMedium, padding, backgroundBrush, outerBorderPen, innerBorderPen, textBrush, textShadowBrush);
                            }
        }
Ejemplo n.º 3
0
        public virtual Image GetResultImage()
        {
            if (Result == RegionResult.Region)
            {
                using (Image img = GetOutputImage())
                {
                    return(RegionCaptureHelpers.ApplyRegionPathToImage(img, regionFillPath));
                }
            }
            else if (Result == RegionResult.Fullscreen)
            {
                return(GetOutputImage());
            }
            else if (Result == RegionResult.Monitor)
            {
                Screen[] screens = Screen.AllScreens;

                if (MonitorIndex < screens.Length)
                {
                    Screen    screen     = screens[MonitorIndex];
                    Rectangle screenRect = CaptureHelpers.ScreenToClient(screen.Bounds);

                    using (Image img = GetOutputImage())
                    {
                        return(ImageHelpers.CropImage(img, screenRect));
                    }
                }
            }
            else if (Result == RegionResult.ActiveMonitor)
            {
                Rectangle activeScreenRect = CaptureHelpers.GetActiveScreenBounds0Based();

                using (Image img = GetOutputImage())
                {
                    return(ImageHelpers.CropImage(img, activeScreenRect));
                }
            }

            return(null);
        }
Ejemplo n.º 4
0
        private void DrawTips(Graphics g)
        {
            StringBuilder sb = new StringBuilder();

            WriteTips(sb);
            string tipText = sb.ToString().Trim();

            Size      textSize      = g.MeasureString(tipText, infoFont).ToSize();
            int       offset        = 10;
            int       padding       = 10;
            int       rectWidth     = textSize.Width + padding * 2 + 2;
            int       rectHeight    = textSize.Height + padding * 2;
            Rectangle screenBounds  = CaptureHelpers.GetActiveScreenBounds0Based();
            Rectangle textRectangle = new Rectangle(screenBounds.X + screenBounds.Width - rectWidth - offset, screenBounds.Y + offset, rectWidth, rectHeight);

            if (textRectangle.Offset(10).Contains(InputManager.MousePosition0Based))
            {
                textRectangle.Y = screenBounds.Height - rectHeight - offset;
            }

            DrawInfoText(g, tipText, textRectangle, infoFont, padding);
        }
Ejemplo n.º 5
0
        private void DrawCursorGraphics(Graphics g)
        {
            Point     mousePos = InputManager.MousePosition0Based;
            Rectangle currentScreenRect0Based = CaptureHelpers.GetActiveScreenBounds0Based();
            int       cursorOffsetX = 10, cursorOffsetY = 10, itemGap = 10, itemCount = 0;
            Size      totalSize = Size.Empty;

            int    magnifierPosition = 0;
            Bitmap magnifier    = null;

            if (Config.ShowMagnifier)
            {
                if (itemCount > 0)
                {
                    totalSize.Height += itemGap;
                }
                magnifierPosition = totalSize.Height;

                magnifier       = Magnifier(Image, mousePos, Config.MagnifierPixelCount, Config.MagnifierPixelCount, Config.MagnifierPixelSize);
                totalSize.Width = Math.Max(totalSize.Width, magnifier.Width);

                totalSize.Height += magnifier.Height;
                itemCount++;
            }

            int       infoTextPadding  = 3;
            int       infoTextPosition = 0;
            Rectangle infoTextRect     = Rectangle.Empty;
            string    infoText         = "";

            if (Config.ShowInfo)
            {
                if (itemCount > 0)
                {
                    totalSize.Height += itemGap;
                }
                infoTextPosition = totalSize.Height;

                CurrentPosition = InputManager.MousePosition;
                infoText        = GetInfoText();
                Size textSize = g.MeasureString(infoText, infoFont).ToSize();
                infoTextRect.Size = new Size(textSize.Width + infoTextPadding * 2, textSize.Height + infoTextPadding * 2);
                totalSize.Width   = Math.Max(totalSize.Width, infoTextRect.Width);

                totalSize.Height += infoTextRect.Height;
                itemCount++;
            }

            int x = mousePos.X + cursorOffsetX;

            if (x + totalSize.Width > currentScreenRect0Based.Right)
            {
                x = mousePos.X - cursorOffsetX - totalSize.Width;
            }

            int y = mousePos.Y + cursorOffsetY;

            if (y + totalSize.Height > currentScreenRect0Based.Bottom)
            {
                y = mousePos.Y - cursorOffsetY - totalSize.Height;
            }

            if (Config.ShowMagnifier)
            {
                using (GraphicsQualityManager quality = new GraphicsQualityManager(g))
                    using (TextureBrush brush = new TextureBrush(magnifier))
                    {
                        brush.TranslateTransform(x, y + magnifierPosition);

                        if (Config.UseSquareMagnifier)
                        {
                            g.FillRectangle(brush, x, y + magnifierPosition, magnifier.Width, magnifier.Height);
                            g.DrawRectangleProper(Pens.White, x - 1, y + magnifierPosition - 1, magnifier.Width + 2, magnifier.Height + 2);
                            g.DrawRectangleProper(Pens.Black, x, y + magnifierPosition, magnifier.Width, magnifier.Height);
                        }
                        else
                        {
                            g.FillEllipse(brush, x, y + magnifierPosition, magnifier.Width, magnifier.Height);
                            g.DrawEllipse(Pens.White, x - 1, y + magnifierPosition - 1, magnifier.Width + 2 - 1, magnifier.Height + 2 - 1);
                            g.DrawEllipse(Pens.Black, x, y + magnifierPosition, magnifier.Width - 1, magnifier.Height - 1);
                        }
                    }
            }

            if (Config.ShowInfo)
            {
                infoTextRect.Location = new Point(x + (totalSize.Width / 2) - (infoTextRect.Width / 2), y + infoTextPosition);
                DrawInfoText(g, infoText, infoTextRect, infoFont, infoTextPadding);
            }
        }
Ejemplo n.º 6
0
        private void DrawFPS(Graphics g, int offset)
        {
            Rectangle screenBounds = CaptureHelpers.GetActiveScreenBounds0Based();

            g.DrawTextWithShadow(FPS.ToString(), screenBounds.Location.Add(offset), infoFontBig, Brushes.White, Brushes.Black, new Point(0, 1));
        }
Ejemplo n.º 7
0
        // Must be called before show form
        public void Prepare(Image img)
        {
            Image = img;

            if (IsEditorMode)
            {
                Rectangle rect = CaptureHelpers.GetActiveScreenBounds0Based();

                if (Image.Width > rect.Width || Image.Height > rect.Height)
                {
                    rect = ScreenRectangle0Based;
                }

                ImageRectangle = new Rectangle(rect.X + rect.Width / 2 - Image.Width / 2, rect.Y + rect.Height / 2 - Image.Height / 2, Image.Width, Image.Height);

                using (Image background = ImageHelpers.DrawCheckers(ScreenRectangle0Based.Width, ScreenRectangle0Based.Height))
                    using (Graphics g = Graphics.FromImage(background))
                    {
                        g.DrawImage(Image, ImageRectangle);

                        backgroundBrush = new TextureBrush(background)
                        {
                            WrapMode = WrapMode.Clamp
                        };
                    }
            }
            else if (Config.UseDimming)
            {
                using (Bitmap darkBackground = (Bitmap)Image.Clone())
                    using (Graphics g = Graphics.FromImage(darkBackground))
                        using (Brush brush = new SolidBrush(Color.FromArgb(30, Color.Black)))
                        {
                            g.FillRectangle(brush, 0, 0, darkBackground.Width, darkBackground.Height);

                            backgroundBrush = new TextureBrush(darkBackground)
                            {
                                WrapMode = WrapMode.Clamp
                            };
                        }

                backgroundHighlightBrush = new TextureBrush(Image)
                {
                    WrapMode = WrapMode.Clamp
                };
            }
            else
            {
                backgroundBrush = new TextureBrush(Image)
                {
                    WrapMode = WrapMode.Clamp
                };
            }

            ShapeManager = new ShapeManager(this);
            ShapeManager.WindowCaptureMode = Config.DetectWindows;
            ShapeManager.IncludeControls   = Config.DetectControls;

            if (Mode == RegionCaptureMode.OneClick || ShapeManager.WindowCaptureMode)
            {
                IntPtr handle = Handle;

                TaskEx.Run(() =>
                {
                    WindowsRectangleList wla = new WindowsRectangleList();
                    wla.IgnoreHandle         = handle;
                    wla.IncludeChildWindows  = ShapeManager.IncludeControls;
                    ShapeManager.Windows     = wla.GetWindowInfoListAsync(5000);
                });
            }

            if (Config.UseCustomInfoText || Mode == RegionCaptureMode.ScreenColorPicker)
            {
                bmpBackgroundImage = new Bitmap(Image);
            }
        }
Ejemplo n.º 8
0
        private void DrawMagnifier(Graphics g)
        {
            Point     mousePos = InputManager.MousePosition0Based;
            Rectangle currentScreenRect0Based = CaptureHelpers.GetActiveScreenBounds0Based();
            int       offsetX = 10, offsetY = 10, infoTextOffset = 0, infoTextPadding = 3;
            Rectangle infoTextRect = Rectangle.Empty;
            string    infoText = "";

            if (Config.ShowInfo)
            {
                infoTextOffset = 10;

                CurrentPosition = InputManager.MousePosition;

                infoText = GetInfoText();
                Size textSize = g.MeasureString(infoText, infoFont).ToSize();
                infoTextRect.Size = new Size(textSize.Width + infoTextPadding * 2, textSize.Height + infoTextPadding * 2);
            }

            using (Bitmap magnifier = Magnifier(backgroundImage, mousePos, Config.MagnifierPixelCount, Config.MagnifierPixelCount, Config.MagnifierPixelSize))
            {
                int x = mousePos.X + offsetX;

                if (x + magnifier.Width > currentScreenRect0Based.Right)
                {
                    x = mousePos.X - offsetX - magnifier.Width;
                }

                int y = mousePos.Y + offsetY;

                if (y + magnifier.Height + infoTextOffset + infoTextRect.Height > currentScreenRect0Based.Bottom)
                {
                    y = mousePos.Y - offsetY - magnifier.Height - infoTextOffset - infoTextRect.Height;
                }

                if (Config.ShowInfo)
                {
                    infoTextRect.Location = new Point(x + (magnifier.Width / 2) - (infoTextRect.Width / 2), y + magnifier.Height + infoTextOffset);
                    DrawInfoText(g, infoText, infoTextRect, infoFont, infoTextPadding);
                }

                g.SetHighQuality();

                using (TextureBrush brush = new TextureBrush(magnifier))
                {
                    brush.TranslateTransform(x, y);

                    if (Config.UseSquareMagnifier)
                    {
                        g.FillRectangle(brush, x, y, magnifier.Width, magnifier.Height);
                        g.DrawRectangleProper(Pens.White, x - 1, y - 1, magnifier.Width + 2, magnifier.Height + 2);
                        g.DrawRectangleProper(Pens.Black, x, y, magnifier.Width, magnifier.Height);
                    }
                    else
                    {
                        g.FillEllipse(brush, x, y, magnifier.Width, magnifier.Height);
                        g.DrawEllipse(Pens.White, x - 1, y - 1, magnifier.Width + 2, magnifier.Height + 2);
                        g.DrawEllipse(Pens.Black, x, y, magnifier.Width, magnifier.Height);
                    }
                }
            }
        }