From 4c0277be90fc31ab5119ba23f716f5a0ad5f771e Mon Sep 17 00:00:00 2001 From: Killy Date: Tue, 28 Apr 2020 19:19:17 +0300 Subject: [PATCH] Robust clip region resize --- Greenshot/Drawing/Surface.cs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Greenshot/Drawing/Surface.cs b/Greenshot/Drawing/Surface.cs index 09bbe028e..a6da5b4ed 100644 --- a/Greenshot/Drawing/Surface.cs +++ b/Greenshot/Drawing/Surface.cs @@ -1406,24 +1406,24 @@ namespace Greenshot.Drawing return GetImage(RenderMode.EXPORT); } - private static Rectangle ZoomClipRectangle(Rectangle rc, double scale) - => new Rectangle( + private static Rectangle ZoomClipRectangle(Rectangle rc, double scale, int inflateAmount = 0) + { + rc = new Rectangle( (int)(rc.X * scale), (int)(rc.Y * scale), - (int)((rc.Width + 1) * scale) + 1, // making sure to redraw enough pixels when moving scaled image - (int)((rc.Height + 1) * scale) + 1 - ); - - private static RectangleF ZoomClipRectangle(RectangleF rc, double scale) - => new RectangleF( - (float)Math.Floor(rc.X * scale), - (float)Math.Floor(rc.Y * scale), - (float)Math.Ceiling(rc.Width * scale), - (float)Math.Ceiling(rc.Height * scale) + (int)(rc.Width * scale) + 1, + (int)(rc.Height * scale) + 1 ); + if (scale > 1) + { + inflateAmount = (int)(inflateAmount * scale); + } + rc.Inflate(inflateAmount, inflateAmount); + return rc; + } public void InvalidateElements(Rectangle rc) - => Invalidate(ZoomClipRectangle(rc, _zoomFactor)); + => Invalidate(ZoomClipRectangle(rc, _zoomFactor, 1)); /// /// This is the event handler for the Paint Event, try to draw as little as possible! @@ -1439,7 +1439,7 @@ namespace Greenshot.Drawing LOG.Debug("Empty cliprectangle??"); return; } - Rectangle imageClipRectangle = ZoomClipRectangle(targetClipRectangle, 1.0 / _zoomFactor); + Rectangle imageClipRectangle = ZoomClipRectangle(targetClipRectangle, 1.0 / _zoomFactor, 2); bool isZoomedIn = ZoomFactor > 1f; if (_elements.HasIntersectingFilters(imageClipRectangle) || isZoomedIn) @@ -1467,7 +1467,7 @@ namespace Greenshot.Drawing //graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; DrawBackground(graphics, imageClipRectangle); graphics.DrawImage(Image, imageClipRectangle, imageClipRectangle, GraphicsUnit.Pixel); - graphics.SetClip(ZoomClipRectangle(targetGraphics.ClipBounds, 1.0 / _zoomFactor)); + graphics.SetClip(ZoomClipRectangle(Rectangle.Round(targetGraphics.ClipBounds), 1.0 / _zoomFactor, 2)); _elements.Draw(graphics, _buffer, RenderMode.EDIT, imageClipRectangle); } targetGraphics.ScaleTransform(_zoomFactor, _zoomFactor);