Fix rendering quality at small zoom levels when redrawing small parts

This commit is contained in:
Killy 2020-04-28 18:55:43 +03:00
commit d47271e7e1

View file

@ -1,4 +1,4 @@
/* /*
* Greenshot - a free and open source screenshot tool * Greenshot - a free and open source screenshot tool
* Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom * Copyright (C) 2007-2020 Thomas Braun, Jens Klingen, Robin Krom
* *
@ -1473,19 +1473,11 @@ namespace Greenshot.Drawing
targetGraphics.ScaleTransform(_zoomFactor, _zoomFactor); targetGraphics.ScaleTransform(_zoomFactor, _zoomFactor);
if (isZoomedIn) if (isZoomedIn)
{ {
var state = targetGraphics.Save(); DrawSharpImage(targetGraphics, _buffer, imageClipRectangle);
targetGraphics.SmoothingMode = SmoothingMode.None;
targetGraphics.InterpolationMode = InterpolationMode.NearestNeighbor;
targetGraphics.CompositingQuality = CompositingQuality.HighQuality;
targetGraphics.PixelOffsetMode = PixelOffsetMode.None;
targetGraphics.DrawImage(_buffer, imageClipRectangle, imageClipRectangle, GraphicsUnit.Pixel);
targetGraphics.Restore(state);
} }
else else
{ {
targetGraphics.DrawImage(_buffer, imageClipRectangle, imageClipRectangle, GraphicsUnit.Pixel); DrawSmoothImage(targetGraphics, _buffer, imageClipRectangle);
} }
targetGraphics.ResetTransform(); targetGraphics.ResetTransform();
} }
@ -1494,7 +1486,7 @@ namespace Greenshot.Drawing
DrawBackground(targetGraphics, targetClipRectangle); DrawBackground(targetGraphics, targetClipRectangle);
targetGraphics.ScaleTransform(_zoomFactor, _zoomFactor); targetGraphics.ScaleTransform(_zoomFactor, _zoomFactor);
targetGraphics.DrawImage(Image, imageClipRectangle, imageClipRectangle, GraphicsUnit.Pixel); DrawSmoothImage(targetGraphics, Image, imageClipRectangle);
_elements.Draw(targetGraphics, null, RenderMode.EDIT, imageClipRectangle); _elements.Draw(targetGraphics, null, RenderMode.EDIT, imageClipRectangle);
targetGraphics.ResetTransform(); targetGraphics.ResetTransform();
} }
@ -1511,6 +1503,32 @@ namespace Greenshot.Drawing
} }
} }
private void DrawSmoothImage(Graphics targetGraphics, Image image, Rectangle imageClipRectangle)
{
var state = targetGraphics.Save();
targetGraphics.SmoothingMode = SmoothingMode.HighQuality;
targetGraphics.InterpolationMode = InterpolationMode.HighQualityBilinear;
targetGraphics.CompositingQuality = CompositingQuality.HighQuality;
targetGraphics.PixelOffsetMode = PixelOffsetMode.None;
targetGraphics.DrawImage(image, imageClipRectangle, imageClipRectangle, GraphicsUnit.Pixel);
targetGraphics.Restore(state);
}
private void DrawSharpImage(Graphics targetGraphics, Image image, Rectangle imageClipRectangle)
{
var state = targetGraphics.Save();
targetGraphics.SmoothingMode = SmoothingMode.None;
targetGraphics.InterpolationMode = InterpolationMode.NearestNeighbor;
targetGraphics.CompositingQuality = CompositingQuality.HighQuality;
targetGraphics.PixelOffsetMode = PixelOffsetMode.None;
targetGraphics.DrawImage(image, imageClipRectangle, imageClipRectangle, GraphicsUnit.Pixel);
targetGraphics.Restore(state);
}
private void DrawBackground(Graphics targetGraphics, Rectangle clipRectangle) private void DrawBackground(Graphics targetGraphics, Rectangle clipRectangle)
{ {
// check if we need to draw the checkerboard // check if we need to draw the checkerboard