mirror of
https://github.com/greenshot/greenshot
synced 2025-08-20 21:43:24 -07:00
Robust clip region resize
This commit is contained in:
parent
d47271e7e1
commit
4c0277be90
1 changed files with 15 additions and 15 deletions
|
@ -1406,24 +1406,24 @@ namespace Greenshot.Drawing
|
||||||
return GetImage(RenderMode.EXPORT);
|
return GetImage(RenderMode.EXPORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Rectangle ZoomClipRectangle(Rectangle rc, double scale)
|
private static Rectangle ZoomClipRectangle(Rectangle rc, double scale, int inflateAmount = 0)
|
||||||
=> new Rectangle(
|
{
|
||||||
|
rc = new Rectangle(
|
||||||
(int)(rc.X * scale),
|
(int)(rc.X * scale),
|
||||||
(int)(rc.Y * scale),
|
(int)(rc.Y * scale),
|
||||||
(int)((rc.Width + 1) * scale) + 1, // making sure to redraw enough pixels when moving scaled image
|
(int)(rc.Width * scale) + 1,
|
||||||
(int)((rc.Height + 1) * scale) + 1
|
(int)(rc.Height * 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)
|
|
||||||
);
|
);
|
||||||
|
if (scale > 1)
|
||||||
|
{
|
||||||
|
inflateAmount = (int)(inflateAmount * scale);
|
||||||
|
}
|
||||||
|
rc.Inflate(inflateAmount, inflateAmount);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
public void InvalidateElements(Rectangle rc)
|
public void InvalidateElements(Rectangle rc)
|
||||||
=> Invalidate(ZoomClipRectangle(rc, _zoomFactor));
|
=> Invalidate(ZoomClipRectangle(rc, _zoomFactor, 1));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is the event handler for the Paint Event, try to draw as little as possible!
|
/// 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??");
|
LOG.Debug("Empty cliprectangle??");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Rectangle imageClipRectangle = ZoomClipRectangle(targetClipRectangle, 1.0 / _zoomFactor);
|
Rectangle imageClipRectangle = ZoomClipRectangle(targetClipRectangle, 1.0 / _zoomFactor, 2);
|
||||||
|
|
||||||
bool isZoomedIn = ZoomFactor > 1f;
|
bool isZoomedIn = ZoomFactor > 1f;
|
||||||
if (_elements.HasIntersectingFilters(imageClipRectangle) || isZoomedIn)
|
if (_elements.HasIntersectingFilters(imageClipRectangle) || isZoomedIn)
|
||||||
|
@ -1467,7 +1467,7 @@ namespace Greenshot.Drawing
|
||||||
//graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
//graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||||
DrawBackground(graphics, imageClipRectangle);
|
DrawBackground(graphics, imageClipRectangle);
|
||||||
graphics.DrawImage(Image, imageClipRectangle, imageClipRectangle, GraphicsUnit.Pixel);
|
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);
|
_elements.Draw(graphics, _buffer, RenderMode.EDIT, imageClipRectangle);
|
||||||
}
|
}
|
||||||
targetGraphics.ScaleTransform(_zoomFactor, _zoomFactor);
|
targetGraphics.ScaleTransform(_zoomFactor, _zoomFactor);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue