protected override void OnPaint(PaintEventArgs e) { mousePos = ScreenHelper.ScreenToClient(ScreenHelper.GetCursorPosition()); activeMonitor = ScreenHelper.GetActiveScreenBounds0Based(); Graphics g = e.Graphics; g.PixelOffsetMode = PixelOffsetMode.HighSpeed; g.InterpolationMode = InterpolationMode.NearestNeighbor; g.SmoothingMode = SmoothingMode.HighQuality; // for some reason highspeed crashes the window g.CompositingQuality = CompositingQuality.HighSpeed; g.CompositingMode = CompositingMode.SourceCopy; g.FillRectangle(backgroundBrush, clientArea); g.CompositingMode = CompositingMode.SourceOver; DrawMouseGraphics(g); if (SettingsManager.RegionCaptureSettings.Draw_Marching_Ants) { borderDotPen.DashOffset += 0.25f; if (borderDotPen.DashOffset > 10) { borderDotPen.DashOffset = 0; } Invalidate(); } }
public RegionReturn(RegionResult result, bool capturedFullscreen, Image image) { Result = result; CapturedScreenBounds = capturedFullscreen; Region = ScreenHelper.GetScreenBounds(); Image = image; }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.SuspendLayout(); this.KeyPreview = true; this.Text = ";3 Image Viewer"; this.StartPosition = FormStartPosition.Manual; this.WindowState = FormWindowState.Normal; this.FormBorderStyle = FormBorderStyle.None; this.Bounds = ScreenHelper.GetActiveScreenBounds(); this.TopMost = true; this.BackColor = Color.Black; ivMain = new ImageDisplay(); ivMain.Dock = DockStyle.Fill; ivMain.DisposeImageOnReplace = false; this.Controls.Add(ivMain); this.KeyDown += ImageViewerForm_KeyDown; this.BringToFront(); this.Activate(); this.ResumeLayout(); }
/// <summary> /// Gets the RegionCaptureInfo for the given region capture. /// </summary> /// <returns> The image/color captured and other info.</returns> public RegionReturn GetRsult() { if (result == RegionResult.Region) { if (leftClickStart.X < leftClickStop.X) { leftClickStop = new Point(leftClickStop.X + 1, leftClickStop.Y); } else { leftClickStop = new Point(leftClickStop.X - 1, leftClickStop.Y); } if (leftClickStart.Y < leftClickStop.Y) { leftClickStop = new Point(leftClickStop.X, leftClickStop.Y + 1); } else { leftClickStop = new Point(leftClickStop.X, leftClickStop.Y - 1); } } switch (result) { case RegionResult.Close: return(new RegionReturn(RegionResult.Close)); case RegionResult.Region: return(new RegionReturn( RegionResult.Region, PointToScreen(leftClickStart), PointToScreen(leftClickStop), Helper.CreateRect(leftClickStart, leftClickStop), ImageProcessor.GetCroppedBitmap(leftClickStart, leftClickStop, image, PixelFormat.Format24bppRgb))); case RegionResult.LastRegion: return(new RegionReturn( RegionResult.LastRegion, LastRegionReturn.StartLeftClick, LastRegionReturn.StopLeftClick, LastRegionReturn.Region, ImageProcessor.GetCroppedBitmap(LastRegionReturn.Region, image, PixelFormat.Format24bppRgb))); case RegionResult.Fullscreen: return(new RegionReturn(RegionResult.Fullscreen, true, image)); case RegionResult.ActiveMonitor: return(new RegionReturn( Screen.FromPoint(ScreenHelper.GetCursorPosition()), ImageProcessor.GetCroppedBitmap(ScreenHelper.GetActiveScreenBounds0Based(), image, PixelFormat.Format24bppRgb))); case RegionResult.Color: return(new RegionReturn( PointToScreen(leftClickStop), image.GetPixel(leftClickStop.X, leftClickStop.Y))); } return(null); }
/// <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)); }
public void DrawCursor(IntPtr hdcDest, Point offset) { if (IsVisible) { Point drawPosition = new Point(Position.X - offset.X, Position.Y - offset.Y); drawPosition = ScreenHelper.ScreenToClient(drawPosition); NativeMethods.DrawIconEx(hdcDest, drawPosition.X, drawPosition.Y, Handle, 0, 0, 0, IntPtr.Zero, NativeConstants.DI_NORMAL); } }
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(); } } }
/// <summary> /// Captures the given rectangle on the screen. /// </summary> /// <param name="rect">The <see cref="Rectangle"/> to capture.</param> /// <returns>A <see cref="Bitmap"/> of the screen region.</returns> public static Bitmap CaptureRectangle(Rectangle rect) { Rectangle bounds = ScreenHelper.GetScreenBounds(); rect = Rectangle.Intersect(bounds, rect); if (UseNativeCapture) { return(CaptureRectangleNative(IntPtr.Zero, rect, CaptureCursor)); } return(ManagedRectAsImage(rect, CaptureCursor)); }
public void DrawCursor(Image img, Point offset) { if (IsVisible) { Point drawPosition = new Point(Position.X - offset.X, Position.Y - offset.Y); drawPosition = ScreenHelper.ScreenToClient(drawPosition); using (Graphics g = Graphics.FromImage(img)) using (Icon icon = Icon.FromHandle(Handle)) { g.DrawIcon(icon, drawPosition.X, drawPosition.Y); } } }
public static bool GetRegionResultColor(out COLOR color) { using (RegionCaptureForm regionCapture = new RegionCaptureForm(ScreenHelper.GetScreenBounds(), RegionCaptureMode.ColorPicker)) { regionCapture.ShowDialog(); LastRegionResult?.Dispose(); LastRegionResult = regionCapture.GetRsult(); if (LastRegionResult.Result == RegionResult.Close) { color = Color.Empty; return(false); } color = LastRegionResult.Color; return(true); } }
public static bool GetRegionResultImage(out Image image) { using (RegionCaptureForm regionCapture = new RegionCaptureForm(ScreenHelper.GetScreenBounds(), RegionCaptureMode.Default)) { regionCapture.ShowDialog(); LastRegionResult?.Dispose(); LastRegionResult = regionCapture.GetRsult(); if (LastRegionResult.Result == RegionResult.Close || LastRegionResult.Image == null) { image = null; return(false); } image = LastRegionResult.Image.CloneSafe(); return(true); } }
private void MouseMove_Event(object sender, MouseEventArgs e) { if (_MagnifierShown) { if (_ZoomRefreshLimiter.ElapsedMilliseconds > Options.ZoomRefreshRate) { DrawZoomedImage(e.Location); _ZoomRefreshLimiter.Restart(); } } else if (_IsResizable && !_IsMoving) { if (_IsResizing) { Point mousepos = ScreenHelper.GetCursorPosition(); switch (_DragLocation) { case DragLoc.Top: ResizeHeight(Height + Location.Y - mousepos.Y); Location = new Point(Location.X, mousepos.Y); break; case DragLoc.Left: ResizeWidth(Width + Location.X - mousepos.X); Location = new Point(mousepos.X, Location.Y); break; case DragLoc.Right: ResizeWidth(mousepos.X - Location.X); break; case DragLoc.Bottom: ResizeHeight(mousepos.Y - Location.Y); break; } Invalidate(); _ZoomControlSize = new Size( (int)Math.Round(ClientSize.Width * SettingsManager.ClipSettings.Zoom_Size_From_Percent), (int)Math.Round(ClientSize.Height * SettingsManager.ClipSettings.Zoom_Size_From_Percent)); } else { Point m = e.Location; if (m.X >= Size.Width - Options.BorderThickness - Options.BorderGrabSize) { Cursor = Cursors.SizeWE; if (_IsLeftClicking) { _DragLocation = DragLoc.Right; _IsResizing = true; } } else if (m.Y >= Size.Height - Options.BorderThickness - Options.BorderGrabSize) { Cursor = Cursors.SizeNS; if (_IsLeftClicking) { _DragLocation = DragLoc.Bottom; _IsResizing = true; } } else if (m.X < Options.BorderThickness + Options.BorderGrabSize) { Cursor = Cursors.SizeWE; if (_IsLeftClicking) { _DragLocation = DragLoc.Left; _IsResizing = true; } } else if (m.Y < Options.BorderThickness + Options.BorderGrabSize) { Cursor = Cursors.SizeNS; if (_IsLeftClicking) { _DragLocation = DragLoc.Top; _IsResizing = true; } } else { Cursor = Cursors.Default; } } } if (_IsLeftClicking && !_IsResizing) { Point p = PointToScreen(e.Location); Location = new Point(p.X - _LastClickLocation.X, p.Y - _LastClickLocation.Y); _IsMoving = true; } }
/// <summary> /// Captures the active monitor. /// </summary> /// <returns>A <see cref="Bitmap"/> of the active monitor.</returns> public static Bitmap CaptureActiveMonitor() { Rectangle bounds = ScreenHelper.GetActiveScreenBounds(); return(CaptureRectangle(bounds)); }
/// <summary> /// Captures the entire screen. /// </summary> /// <returns>A <see cref="Bitmap"/> of the screen.</returns> public static Bitmap CaptureFullscreen() { Rectangle bounds = ScreenHelper.GetScreenBounds(); return(CaptureRectangle(bounds)); }
public RegionCaptureForm() : this(ScreenHelper.GetScreenBounds(), SettingsManager.RegionCaptureSettings.Mode) { }