From 46156d612bff33ae7639edb956b5a42588cef36e Mon Sep 17 00:00:00 2001 From: Jaex Date: Sun, 7 May 2017 01:22:26 +0300 Subject: [PATCH] Use ImageRectangle in CropImage method --- .../Shapes/ShapeManager.cs | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs b/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs index 1dda7a23d..bdfa78620 100644 --- a/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs +++ b/ShareX.ScreenCaptureLib/Shapes/ShapeManager.cs @@ -1231,6 +1231,16 @@ public void DrawRegionArea(Graphics g, Rectangle rect) } public void CropArea(Rectangle rect) + { + Image img = CropImage(rect, true); + + if (img != null) + { + form.InitBackground(img); + } + } + + public Image CropImage(Rectangle rect, bool onlyIfSizeDifferent = false) { rect.X -= form.ImageRectangle.X; rect.Y -= form.ImageRectangle.Y; @@ -1239,23 +1249,7 @@ public void CropArea(Rectangle rect) rect.Intersect(new Rectangle(0, 0, form.Image.Width, form.Image.Height)); - if (rect.IsValid() && rect.Size != form.Image.Size) - { - Image img = ImageHelpers.CropImage(form.Image, rect); - - if (img != null) - { - form.InitBackground(img); - } - } - } - - public Image CropImage(Rectangle rect) - { - rect = CaptureHelpers.ScreenToClient(rect); - rect.Intersect(new Rectangle(0, 0, form.Image.Width, form.Image.Height)); - - if (rect.IsValid()) + if (rect.IsValid() && (!onlyIfSizeDifferent || rect.Size != form.Image.Size)) { return ImageHelpers.CropImage(form.Image, rect); }