コード例 #1
0
        /// <summary>
        /// Creates a new clip at the cursor.
        /// </summary>
        /// <param name="img">The image to display. </param>
        /// <param name="cloneImage">If the image should be cloned to avoid disposing issues.</param>
        /// <returns></returns>
        public static string CreateClipAtCursor(Image img, bool cloneImage = true)
        {
            Point p = ScreenHelper.GetCursorPosition();

            ClipOptions ops = new ClipOptions(new Point(p.X - img.Width / 2, p.Y - img.Height / 2));

            return(CreateClip(img, ops, cloneImage));
        }
コード例 #2
0
        public static void RegionCapture(RegionCaptureMode mode, bool creatClip = false)
        {
            using (RegionCaptureForm regionCapture = new RegionCaptureForm(ScreenHelper.GetScreenBounds(), mode))
            {
                regionCapture.ShowDialog();

                LastRegionResult?.Dispose();
                LastRegionResult = regionCapture.GetRsult();


                if (LastRegionResult.Result == RegionResult.Close)
                {
                    return;
                }

                if (LastRegionResult.Result == RegionResult.Color)
                {
                    if (SettingsManager.RegionCaptureSettings.Auto_Copy_Color)
                    {
                        ClipboardHelper.FormatCopyColor(SettingsManager.MiscSettings.Default_Color_Format, LastRegionResult.Color);
                    }
                    return;
                }

                if (SettingsManager.RegionCaptureSettings.Auto_Copy_Image)
                {
                    ClipboardHelper.CopyImage(LastRegionResult.Image);
                }

                string path = string.Empty;

                if (InternalSettings.Save_Images_To_Disk)
                {
                    path = PathHelper.GetNewImageFileName();
                }

                if (creatClip)
                {
                    ClipOptions ops = new ClipOptions(ScreenHelper.GetRectangle0Based(LastRegionResult.Region).Location);
                    ops.FilePath = path;
                    ClipManager.CreateClip(LastRegionResult.Image, ops);
                }

                if (InternalSettings.Save_Images_To_Disk)
                {
                    Save(path, LastRegionResult.Image);
                }

                if (LastRegionResult.Image != null)
                {
                    LastRegionResult.Image.Dispose();
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Creates a new clip from the given image with the given options.
        /// </summary>
        /// <param name="clipImg">The image to display. </param>
        /// <param name="options">The options to use.</param>
        /// <param name="cloneImage">If the image should be cloned to avoid disposing issues.</param>
        /// <returns></returns>
        public static string CreateClip(Image clipImg, ClipOptions options, bool cloneImage = true)
        {
            if (cloneImage)
            {
                Clips[options.Name] = new ClipForm(options, clipImg.CloneSafe());
            }
            else
            {
                Clips[options.Name] = new ClipForm(options, clipImg);
            }

            return(options.Name);
        }
コード例 #4
0
        public ClipForm(ClipOptions options, Image image)
        {
            SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
            InitializeComponent();
            SuspendLayout();

            Options = options;

            ClipName = Options.Name;

            _ChangeTracker = new BitmapUndo(IMAGE.ProperCast(image, InternalSettings.Default_Image_Format));

            _AspectRatio = image.Width / (double)image.Height;

            StartWindowSize = new Size(
                image.Width + (Options.BorderThickness << 1),
                image.Height + (Options.BorderThickness << 1));

            _ZoomControlSize = new Size(
                (int)Math.Round(StartWindowSize.Width * SettingsManager.ClipSettings.Zoom_Size_From_Percent),
                (int)Math.Round(StartWindowSize.Height * SettingsManager.ClipSettings.Zoom_Size_From_Percent));

            MinimumSize = StartWindowSize;
            MaximumSize = StartWindowSize;


            Bounds    = new Rectangle(options.Location, StartWindowSize);
            BackColor = Options.Color;

            zdbZoomedImageDisplay.Enabled            = false;
            zdbZoomedImageDisplay.borderColor        = SettingsManager.ClipSettings.Border_Color;
            zdbZoomedImageDisplay.replaceTransparent = SettingsManager.ClipSettings.Zoom_Color;
            if (SettingsManager.ClipSettings.Zoom_Size_From_Percent == 1f)
            {
                zdbZoomedImageDisplay.BorderThickness = 0;
            }
            else
            {
                zdbZoomedImageDisplay.BorderThickness = SettingsManager.ClipSettings.Zoom_Border_Thickness;
            }


            MouseDown  += MouseDown_Event;
            MouseUp    += MouseUp_Event;
            MouseMove  += MouseMove_Event;
            ResizeEnd  += ResizeEnded;
            KeyDown    += FormKeyDown;
            MouseWheel += ClipForm_MouseWheel;

            base.PreventHide = SettingsManager.ClipSettings.Never_Hide_Clips;
            base.RegisterEvents();

            #region context menu
            cmMain.Opening += CmMain_Opening;
            tsmiCopyToolStripMenuItem.Click            += CopyImage_Click;
            tsmiAllowResizeToolStripMenuItem.Click     += AllowResize_Click;
            tsmiOCRToolStripMenuItem.Click             += OCR_Click;
            tsmiSaveToolStripMenuItem.Click            += Save_Click;
            tsmiDestroyToolStripMenuItem.Click         += Destroy_Click;
            tsmiDestroyAllClipsToolStripMenuItem.Click += DestroyAllClips_Click;

            tsmiCopyDefaultContextMenuItem.Click    += CopyImage_Click;
            tsmiCopyZoomScaledContextMenuItem.Click += CopyScaledImage_Click;
            tsmiCopyZoomedImage.Click += CopyZoomedImage_Click;

            tsmiOpenInEditor.Click   += OpenInEditor_Click;
            tsmiInvertColor.Click    += InvertColor_Click;
            tsmiConvertToGray.Click  += ConvertToGray_Click;
            tsmiRotateLeft.Click     += RotateLeft_Click;
            tsmiRotateRight.Click    += RotateRight_Click;
            tsmiFlipHorizontal.Click += FlipHorizontal_Click;
            tsmiFlipVertical.Click   += FlipVertical_Click;

            if (_IsResizable)
            {
                tsmiAllowResizeToolStripMenuItem.Checked = true;
            }
            #endregion

            Text = ClipName;

            ResumeLayout(true);

            Show();

            UpdateTheme();

            TopMost = true;

            //for some reason if the clip is on a display that is scaled it makes it bigger than its supposed to be
            //so only allow it to be resized after 1000 ms
            Timer updateMaxSizeTimer = new Timer()
            {
                Interval = 1000
            };
            updateMaxSizeTimer.Tick += UpdateMaxSizeTimerTick_Event;
            updateMaxSizeTimer.Start();
        }