修复bug,缩放不是100%时出错,比如125%

This commit is contained in:
noctwolf committed 2019-07-20 17:36:44 +08:00
1 parent e722fa6fd0
commit 0ae2576c60
1 file changed
+6 -5
@@ -154,23 +154,24 @@ namespace HandyControl.Controls
if (Source != null && Source is BitmapSource source)
{
// ReSharper disable once AssignNullToNotNullAttribute
var croppedBitmap = new CroppedBitmap(source, CalDisplayRect());
var croppedBitmap = new CroppedBitmap(source,
CalDisplayRect(source.PixelWidth / Columns, source.PixelHeight / Rows));
dc.DrawImage(croppedBitmap, new Rect(0, 0, RenderSize.Width, RenderSize.Height));
}
}
private Int32Rect CalDisplayRect()
private Int32Rect CalDisplayRect(int width, int height)
{
if (_currentIndex > _indexMax)
{
_currentIndex = _indexMin;
}
var x = (int) (_currentIndex % Columns * RenderSize.Width);
var x = _currentIndex % Columns * width;
// ReSharper disable once PossibleLossOfFraction
var y = (int) (_currentIndex / Columns * RenderSize.Height);
var y = _currentIndex / Columns * height;
var rect = new Int32Rect(x, y, (int)RenderSize.Width, (int)RenderSize.Height);
var rect = new Int32Rect(x, y, width, height);
_currentIndex++;
return rect;
}