示例#1
0
        public static PointInfo SelectPointColor(SurfaceOptions surfaceOptions = null)
        {
            if (surfaceOptions == null)
            {
                surfaceOptions = new SurfaceOptions();
            }

            using (Image fullscreen = Screenshot.CaptureFullscreen())
                using (RectangleRegion surface = new RectangleRegion(fullscreen))
                {
                    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)fullscreen).GetPixel(surface.OneClickPosition.X, surface.OneClickPosition.Y);
                        return(pointInfo);
                    }
                }

            return(null);
        }
示例#2
0
 private void CaptureLastRegion(TaskSettings taskSettings, bool autoHideForm = true)
 {
     if (!taskSettings.AdvancedSettings.UseLightRectangleCrop && Surface.LastRegionFillPath != null)
     {
         DoCapture(() =>
         {
             using (Image screenshot = Screenshot.CaptureFullscreen())
             {
                 return(ShapeCaptureHelpers.GetRegionImage(screenshot, Surface.LastRegionFillPath, Surface.LastRegionDrawPath, taskSettings.CaptureSettings.SurfaceOptions));
             }
         }, CaptureType.LastRegion, taskSettings, autoHideForm);
     }
     else if (taskSettings.AdvancedSettings.UseLightRectangleCrop && !RectangleLight.LastSelectionRectangle0Based.IsEmpty)
     {
         DoCapture(() =>
         {
             using (Image screenshot = Screenshot.CaptureFullscreen())
             {
                 return(ImageHelpers.CropImage(screenshot, RectangleLight.LastSelectionRectangle0Based));
             }
         }, CaptureType.LastRegion, taskSettings, autoHideForm);
     }
     else
     {
         CaptureRegion(CaptureType.Rectangle, taskSettings, autoHideForm);
     }
 }
示例#3
0
        protected TaskMetadata ExecuteRegionCaptureLight(TaskSettings taskSettings)
        {
            Bitmap     canvas;
            Screenshot screenshot = TaskHelpers.GetScreenshot(taskSettings);

            if (taskSettings.CaptureSettings.SurfaceOptions.ActiveMonitorMode)
            {
                canvas = screenshot.CaptureActiveMonitor();
            }
            else
            {
                canvas = screenshot.CaptureFullscreen();
            }

            bool activeMonitorMode = taskSettings.CaptureSettings.SurfaceOptions.ActiveMonitorMode;

            using (RegionCaptureLightForm rectangleLight = new RegionCaptureLightForm(canvas, activeMonitorMode))
            {
                if (rectangleLight.ShowDialog() == DialogResult.OK)
                {
                    Bitmap result = rectangleLight.GetAreaImage();

                    if (result != null)
                    {
                        lastRegionCaptureType = RegionCaptureType.Light;

                        return(new TaskMetadata(result));
                    }
                }
            }

            return(null);
        }
示例#4
0
        protected ImageInfo ExecuteRegionCapture(TaskSettings taskSettings)
        {
            ImageInfo imageInfo = new ImageInfo();

            RegionCaptureMode mode;

            if (taskSettings.AdvancedSettings.RegionCaptureDisableAnnotation)
            {
                mode = RegionCaptureMode.Default;
            }
            else
            {
                mode = RegionCaptureMode.Annotation;
            }

            Screenshot screenshot = TaskHelpers.GetScreenshot(taskSettings);

            screenshot.CaptureCursor = false;
            Image img = screenshot.CaptureFullscreen();

            CursorData cursorData = null;

            if (taskSettings.CaptureSettings.ShowCursor)
            {
                cursorData = new CursorData();
            }

            using (RegionCaptureForm form = new RegionCaptureForm(mode, taskSettings.CaptureSettingsReference.SurfaceOptions, img))
            {
                if (cursorData != null && cursorData.IsValid)
                {
                    form.AddCursor(cursorData.Handle, cursorData.Position);
                    cursorData.Dispose();
                }

                form.ShowDialog();

                imageInfo.Image = form.GetResultImage();

                if (imageInfo.Image != null)
                {
                    if (form.IsModified)
                    {
                        AllowAnnotation = false;
                    }

                    if (form.Result == RegionResult.Region && taskSettings.UploadSettings.RegionCaptureUseWindowPattern)
                    {
                        WindowInfo windowInfo = form.GetWindowInfo();
                        imageInfo.UpdateInfo(windowInfo);
                    }

                    lastRegionCaptureType = RegionCaptureType.Default;
                }
            }

            return(imageInfo);
        }
示例#5
0
        protected TaskMetadata ExecuteRegionCapture(TaskSettings taskSettings)
        {
            TaskMetadata metadata = new TaskMetadata();

            RegionCaptureMode mode;

            if (taskSettings.AdvancedSettings.RegionCaptureDisableAnnotation)
            {
                mode = RegionCaptureMode.Default;
            }
            else
            {
                mode = RegionCaptureMode.Annotation;
            }

            Screenshot screenshot = TaskHelpers.GetScreenshot(taskSettings);

            screenshot.CaptureCursor = false;
            Bitmap bmp = screenshot.CaptureFullscreen();

            CursorData cursorData = null;

            if (taskSettings.CaptureSettings.ShowCursor)
            {
                cursorData = new CursorData();
            }

            using (RegionCaptureForm form = new RegionCaptureForm(mode, taskSettings.CaptureSettingsReference.SurfaceOptions, bmp))
            {
                if (cursorData != null && cursorData.IsVisible)
                {
                    form.AddCursor(cursorData.Handle, CaptureHelpers.ScreenToClient(cursorData.Position));
                }

                form.ShowDialog();

                metadata.Image = form.GetResultImage();

                if (metadata.Image != null)
                {
                    if (form.IsImageModified)
                    {
                        AllowAnnotation = false;
                    }

                    if (form.Result == RegionResult.Region)
                    {
                        WindowInfo windowInfo = form.GetWindowInfo();
                        metadata.UpdateInfo(windowInfo);
                    }

                    lastRegionCaptureType = RegionCaptureType.Default;
                }
            }

            return(metadata);
        }
示例#6
0
文件: MainForm.cs 项目: Z1ni/ShareX
 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();
         }
 }
示例#7
0
 private void CaptureLastRegion(TaskSettings taskSettings, bool autoHideForm = true)
 {
     if (Surface.LastRegionFillPath != null)
     {
         DoCapture(() =>
         {
             using (Image screenshot = Screenshot.CaptureFullscreen())
             {
                 return(ShapeCaptureHelpers.GetRegionImage(screenshot, Surface.LastRegionFillPath, Surface.LastRegionDrawPath, taskSettings.CaptureSettings.SurfaceOptions));
             }
         }, CaptureType.LastRegion, taskSettings, autoHideForm);
     }
     else
     {
         CaptureRegion(CaptureType.Rectangle, taskSettings, autoHideForm);
     }
 }
示例#8
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);
        }
示例#9
0
        protected TaskMetadata ExecuteRegionCapture(TaskSettings taskSettings)
        {
            RegionCaptureMode mode;

            if (taskSettings.AdvancedSettings.RegionCaptureDisableAnnotation)
            {
                mode = RegionCaptureMode.Default;
            }
            else
            {
                mode = RegionCaptureMode.Annotation;
            }

            Bitmap     canvas;
            Screenshot screenshot = TaskHelpers.GetScreenshot(taskSettings);

            screenshot.CaptureCursor = false;

            if (taskSettings.CaptureSettings.SurfaceOptions.ActiveMonitorMode)
            {
                canvas = screenshot.CaptureActiveMonitor();
            }
            else
            {
                canvas = screenshot.CaptureFullscreen();
            }

            CursorData cursorData = null;

            if (taskSettings.CaptureSettings.ShowCursor)
            {
                cursorData = new CursorData();
            }

            using (RegionCaptureForm form = new RegionCaptureForm(mode, taskSettings.CaptureSettingsReference.SurfaceOptions, canvas))
            {
                if (cursorData != null && cursorData.IsVisible)
                {
                    form.AddCursor(cursorData.ToBitmap(), form.PointToClient(cursorData.DrawPosition));
                }

                form.ShowDialog();

                Bitmap result = form.GetResultImage();

                if (result != null)
                {
                    TaskMetadata metadata = new TaskMetadata(result);

                    if (form.IsImageModified)
                    {
                        AllowAnnotation = false;
                    }

                    if (form.Result == RegionResult.Region)
                    {
                        WindowInfo windowInfo = form.GetWindowInfo();
                        metadata.UpdateInfo(windowInfo);
                    }

                    lastRegionCaptureType = RegionCaptureType.Default;

                    return(metadata);
                }
            }

            return(null);
        }