Example #1
0
        public static bool SelectRegion(out Rectangle rect, TaskSettings taskSettings)
        {
            using (RectangleRegion surface = new RectangleRegion())
            {
                surface.Config                    = taskSettings.CaptureSettings.SurfaceOptions;
                surface.Config.QuickCrop          = true;
                surface.Config.ForceWindowCapture = true;
                surface.Prepare();
                surface.ShowDialog();

                if (surface.Result == SurfaceResult.Region)
                {
                    if (surface.AreaManager.IsCurrentAreaValid)
                    {
                        rect = CaptureHelpers.ClientToScreen(surface.AreaManager.CurrentArea);
                        return(true);
                    }
                }
                else if (surface.Result == SurfaceResult.Fullscreen)
                {
                    rect = CaptureHelpers.GetScreenBounds();
                    return(true);
                }
            }

            rect = Rectangle.Empty;
            return(false);
        }
Example #2
0
        private void ButtonSendScreenshot_Click(object sender, RoutedEventArgs e)
        {
            using (var screenshot = Screenshot.CaptureFullscreen())
                using (var surface = new RectangleRegion())
                {
                    surface.SurfaceImage = screenshot;
                    surface.Prepare();
                    surface.ShowDialog();

                    using (var img = surface.GetRegionImage())
                    {
                        if (img == null)
                        {
                            return;
                        }

                        var stream = new MemoryStream();
                        img.Save(stream, ImageFormat.Png);

                        var transfer = ProfileManager.Instance.TransferManager.SendFile(Context.Friend.ChatNumber, stream, "screenshot.png");
                        if (transfer == null)
                        {
                            MessageBox.Show("Could not send screenshot.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                            return;
                        }

                        (Context.Friend.ConversationView as ConversationViewModel).AddTransfer(transfer);
                    }
                }
        }
Example #3
0
        private void WindowRectangleCapture(bool autoHideForm = true)
        {
            RectangleRegion rectangleRegion = new RectangleRegion();

            rectangleRegion.AreaManager.WindowCaptureMode = true;
            CaptureRegion(rectangleRegion, autoHideForm);
        }
Example #4
0
        public static PointInfo SelectPointColor(SurfaceOptions surfaceOptions = null)
        {
            if (surfaceOptions == null)
            {
                surfaceOptions = new SurfaceOptions();
            }

            using (RectangleRegion surface = new RectangleRegion())
            {
                surface.Config       = surfaceOptions;
                surface.OneClickMode = true;
                surface.Prepare();
                surface.ShowDialog();

                if (surface.Result == SurfaceResult.Region)
                {
                    PointInfo pointInfo = new PointInfo();
                    pointInfo.Position = CaptureHelpers.ClientToScreen(surface.OneClickPosition);
                    pointInfo.Color    = ((Bitmap)surface.SurfaceImage).GetPixel(surface.OneClickPosition.X, surface.OneClickPosition.Y);
                    return(pointInfo);
                }
            }

            return(null);
        }
Example #5
0
        public static bool SelectRegion(out Rectangle rect)
        {
            using (RectangleRegion surface = new RectangleRegion())
            {
                surface.AreaManager.WindowCaptureMode = true;
                surface.AreaManager.IncludeControls   = true;
                surface.Prepare();
                surface.ShowDialog();

                if (surface.Result == SurfaceResult.Region)
                {
                    if (surface.AreaManager.IsCurrentAreaValid)
                    {
                        rect = CaptureHelpers.ClientToScreen(surface.AreaManager.CurrentArea);
                        return(true);
                    }
                }
                else if (surface.Result == SurfaceResult.Fullscreen)
                {
                    rect = CaptureHelpers.GetScreenBounds();
                    return(true);
                }
            }

            rect = Rectangle.Empty;
            return(false);
        }
Example #6
0
        public static PointInfo SelectPointColor(SurfaceOptions surfaceOptions = null)
        {
            using (Image fullscreen = Screenshot.CaptureFullscreen())
                using (RectangleRegion surface = new RectangleRegion(fullscreen))
                {
                    if (surfaceOptions != null)
                    {
                        surface.Config = new SurfaceOptions
                        {
                            MagnifierPixelCount = surfaceOptions.MagnifierPixelCount,
                            MagnifierPixelSize  = surfaceOptions.MagnifierPixelSize
                        };
                    }

                    surface.OneClickMode = true;
                    surface.Prepare();
                    surface.ShowDialog();

                    if (surface.Result == SurfaceResult.Region)
                    {
                        PointInfo pointInfo = new PointInfo();
                        pointInfo.Position = CaptureHelpers.ClientToScreen(surface.OneClickPosition);
                        pointInfo.Color    = ((Bitmap)fullscreen).GetPixel(surface.OneClickPosition.X, surface.OneClickPosition.Y);
                        return(pointInfo);
                    }
                }

            return(null);
        }
Example #7
0
 public static void OpenRuler()
 {
     using (Image fullscreen = Screenshot.CaptureFullscreen())
         using (RectangleRegion surface = new RectangleRegion(fullscreen))
         {
             surface.RulerMode        = true;
             surface.Config.QuickCrop = false;
             surface.Prepare();
             surface.ShowDialog();
         }
 }
Example #8
0
 public static void OpenRuler()
 {
     using (RectangleRegion surface = new RectangleRegion())
     {
         surface.RulerMode               = true;
         surface.Config.QuickCrop        = false;
         surface.Config.ShowInfo         = true;
         surface.AreaManager.MinimumSize = 3;
         surface.Prepare();
         surface.ShowDialog();
     }
 }
Example #9
0
 public static void OpenRuler()
 {
     using (Image fullscreen = new CaptureFullScreen().Screenshot())
         using (RectangleRegion surface = new RectangleRegion(fullscreen))
         {
             surface.RulerMode               = true;
             surface.Config.QuickCrop        = false;
             surface.Config.ShowInfo         = true;
             surface.AreaManager.MinimumSize = 3;
             surface.Prepare();
             surface.ShowDialog();
         }
 }
Example #10
0
        public AreaManager(RectangleRegion surface)
        {
            this.surface = surface;
            ResizeManager = new ResizeManager(surface, this);

            Areas = new List<RegionInfo>();
            SelectedAreaIndex = -1;
            RoundedRectangleRadius = 25;
            RoundedRectangleRadiusIncrement = 3;
            TriangleAngle = TriangleAngle.Top;
            MinimumSize = 10;

            surface.MouseDown += surface_MouseDown;
            surface.MouseUp += surface_MouseUp;
            surface.KeyDown += surface_KeyDown;
            surface.KeyUp += surface_KeyUp;
        }
    public Aurigma.GraphicsMill.Bitmap RenderRegion(string regionName, float dpi)
    {
        Layer        renderedLayer = null;
        List <Layer> hiddenLayers  = new List <Layer>(_canvasViewer.Canvas.Layers.Count);

        foreach (Layer l in _canvasViewer.Canvas.Layers)
        {
            if (l.Name == regionName)
            {
                renderedLayer = l;
            }
            else if (l.Visible)
            {
                l.Visible = false;
                hiddenLayers.Add(l);
            }
        }
        if (renderedLayer == null)
        {
            //TODO: throw exception
        }

        // Temporary remove region from rendered layer.
        RectangleRegion rr = renderedLayer.Region;

        renderedLayer.Region = null;

        //render canvas
        Aurigma.GraphicsMill.Bitmap bp = _canvasViewer.Canvas.RenderWorkspace(dpi, Aurigma.GraphicsMill.ColorSpace.Rgb);

        // Restore region back.
        renderedLayer.Region = rr;

        //crop region
        Rectangle r = new Rectangle(Common.ConvertPointsToPixels(dpi, renderedLayer.Region.Left),
                                    Common.ConvertPointsToPixels(dpi, renderedLayer.Region.Top),
                                    Common.ConvertPointsToPixels(dpi, renderedLayer.Region.Width),
                                    Common.ConvertPointsToPixels(dpi, renderedLayer.Region.Height));

        bp.Transforms.Crop(r);

        //revert hidden layers
        hiddenLayers.ForEach(delegate(Layer l) { l.Visible = true; });
        return(bp);
    }
Example #12
0
        public static bool SelectRegion(out Rectangle rect, TaskSettings taskSettings)
        {
            using (RectangleRegion surface = new RectangleRegion())
            {
                surface.Config                    = taskSettings.CaptureSettings.SurfaceOptions;
                surface.Config.ShowTips           = false;
                surface.Config.QuickCrop          = true;
                surface.Config.ForceWindowCapture = true;
                surface.Prepare();
                surface.ShowDialog();

                if (surface.Result == SurfaceResult.Region)
                {
                    if (surface.AreaManager.IsCurrentAreaValid)
                    {
                        rect = CaptureHelpers.ClientToScreen(surface.AreaManager.CurrentArea);
                        return(true);
                    }
                }
                else if (surface.Result == SurfaceResult.Fullscreen)
                {
                    rect = CaptureHelpers.GetScreenBounds();
                    return(true);
                }
                else if (surface.Result == SurfaceResult.Monitor)
                {
                    Screen[] screens = Screen.AllScreens;

                    if (surface.MonitorIndex < screens.Length)
                    {
                        Screen screen = screens[surface.MonitorIndex];
                        rect = screen.Bounds;
                        return(true);
                    }
                }
                else if (surface.Result == SurfaceResult.ActiveMonitor)
                {
                    rect = CaptureHelpers.GetActiveScreenBounds();
                    return(true);
                }
            }

            rect = Rectangle.Empty;
            return(false);
        }
Example #13
0
        public static PointInfo SelectPointColor()
        {
            using (RectangleRegion surface = new RectangleRegion())
            {
                surface.OneClickMode = true;
                surface.Prepare();
                surface.ShowDialog();

                if (surface.Result == SurfaceResult.Region)
                {
                    PointInfo pointInfo = new PointInfo();
                    pointInfo.Position = CaptureHelpers.ClientToScreen(surface.CurrentPosition);
                    pointInfo.Color    = surface.CurrentColor;
                    return(pointInfo);
                }
            }

            return(null);
        }
Example #14
0
        public static PointInfo SelectPointColor()
        {
            using (RectangleRegion surface = new RectangleRegion())
            {
                surface.ScreenColorPickerMode = true;
                surface.Config.UseDimming     = false;
                surface.Config.ShowInfo       = true;
                surface.Config.ShowMagnifier  = true;
                surface.Config.ShowTips       = false;
                surface.Prepare();
                surface.ShowDialog();

                if (surface.Result == SurfaceResult.Region)
                {
                    PointInfo pointInfo = new PointInfo();
                    pointInfo.Position = surface.CurrentPosition;
                    pointInfo.Color    = surface.CurrentColor;
                    return(pointInfo);
                }
            }

            return(null);
        }
Example #15
0
        public static PointInfo SelectPointColor()
        {
            using (RectangleRegion surface = new RectangleRegion())
            {
                surface.ScreenColorPickerMode = true;
                surface.Config.UseDimming = false;
                surface.Config.ShowInfo = true;
                surface.Config.ShowMagnifier = true;
                surface.Config.ShowTips = false;
                surface.Prepare();
                surface.ShowDialog();

                if (surface.Result == SurfaceResult.Region)
                {
                    PointInfo pointInfo = new PointInfo();
                    pointInfo.Position = surface.CurrentPosition;
                    pointInfo.Color = surface.CurrentColor;
                    return pointInfo;
                }
            }

            return null;
        }
Example #16
0
        public static bool SelectRegion(out Rectangle rect, TaskSettings taskSettings)
        {
            using (RectangleRegion surface = new RectangleRegion())
            {
                surface.Config = taskSettings.CaptureSettings.SurfaceOptions;
                surface.Config.ShowTips = false;
                surface.Config.QuickCrop = true;
                surface.Config.ForceWindowCapture = true;
                surface.Prepare();
                surface.ShowDialog();

                if (surface.Result == SurfaceResult.Region)
                {
                    if (surface.AreaManager.IsCurrentAreaValid)
                    {
                        rect = CaptureHelpers.ClientToScreen(surface.AreaManager.CurrentArea);
                        return true;
                    }
                }
                else if (surface.Result == SurfaceResult.Fullscreen)
                {
                    rect = CaptureHelpers.GetScreenBounds();
                    return true;
                }
                else if (surface.Result == SurfaceResult.Monitor)
                {
                    Screen[] screens = Screen.AllScreens;

                    if (surface.MonitorIndex < screens.Length)
                    {
                        Screen screen = screens[surface.MonitorIndex];
                        rect = screen.Bounds;
                        return true;
                    }
                }
                else if (surface.Result == SurfaceResult.ActiveMonitor)
                {
                    rect = CaptureHelpers.GetActiveScreenBounds();
                    return true;
                }
            }

            rect = Rectangle.Empty;
            return false;
        }
Example #17
0
        private void CaptureRegion(CaptureType captureType, TaskSettings taskSettings, bool autoHideForm = true)
        {
            Surface surface;

            switch (captureType)
            {
            default:
            case CaptureType.Rectangle:
                if (taskSettings.AdvancedSettings.UseLightRectangleCrop)
                {
                    CaptureLightRectangle(taskSettings, autoHideForm);
                    return;
                }

                surface = new RectangleRegion();
                break;

            case CaptureType.RectangleWindow:
                RectangleRegion rectangleRegion = new RectangleRegion();
                rectangleRegion.AreaManager.WindowCaptureMode = true;
                surface = rectangleRegion;
                break;

            case CaptureType.RoundedRectangle:
                surface = new RoundedRectangleRegion();
                break;

            case CaptureType.Ellipse:
                surface = new EllipseRegion();
                break;

            case CaptureType.Triangle:
                surface = new TriangleRegion();
                break;

            case CaptureType.Diamond:
                surface = new DiamondRegion();
                break;

            case CaptureType.Polygon:
                surface = new PolygonRegion();
                break;

            case CaptureType.Freehand:
                surface = new FreeHandRegion();
                break;
            }

            DoCapture(() =>
            {
                Image img        = null;
                Image screenshot = Screenshot.CaptureFullscreen();

                try
                {
                    surface.Config       = taskSettings.CaptureSettings.SurfaceOptions;
                    surface.SurfaceImage = screenshot;
                    surface.Prepare();
                    surface.ShowDialog();

                    if (surface.Result == SurfaceResult.Region)
                    {
                        img = surface.GetRegionImage();
                        screenshot.Dispose();
                    }
                    else if (surface.Result == SurfaceResult.Fullscreen)
                    {
                        img = screenshot;
                    }
                }
                finally
                {
                    surface.Dispose();
                }

                return(img);
            }, captureType, taskSettings, autoHideForm);
        }
Example #18
0
 public static void OpenRuler()
 {
     using (RectangleRegion surface = new RectangleRegion())
     {
         surface.RulerMode = true;
         surface.Config.ShowTips = false;
         surface.Config.QuickCrop = false;
         surface.Config.ShowInfo = true;
         surface.AreaManager.MinimumSize = 3;
         surface.Prepare();
         surface.ShowDialog();
     }
 }