fix:issue #287
This commit is contained in:
@@ -281,8 +281,16 @@ namespace Ink_Canvas.Helpers
|
|||||||
// 应用旋转
|
// 应用旋转
|
||||||
Bitmap rotatedFrame = ApplyRotation(sourceFrame);
|
Bitmap rotatedFrame = ApplyRotation(sourceFrame);
|
||||||
|
|
||||||
// 应用分辨率调整
|
int targetWidth = _resolutionWidth;
|
||||||
_currentFrame = ResizeImage(rotatedFrame, _resolutionWidth, _resolutionHeight);
|
int targetHeight = _resolutionHeight;
|
||||||
|
|
||||||
|
if (_rotationAngle == 1 || _rotationAngle == 3)
|
||||||
|
{
|
||||||
|
targetWidth = _resolutionHeight;
|
||||||
|
targetHeight = _resolutionWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
_currentFrame = ResizeImageWithAspectRatio(rotatedFrame, targetWidth, targetHeight);
|
||||||
|
|
||||||
rotatedFrame?.Dispose();
|
rotatedFrame?.Dispose();
|
||||||
}
|
}
|
||||||
@@ -357,6 +365,33 @@ namespace Ink_Canvas.Helpers
|
|||||||
return rotated;
|
return rotated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 调整图像大小
|
||||||
|
/// </summary>
|
||||||
|
private Bitmap ResizeImageWithAspectRatio(Bitmap source, int targetWidth, int targetHeight)
|
||||||
|
{
|
||||||
|
if (source.Width == targetWidth && source.Height == targetHeight)
|
||||||
|
return new Bitmap(source);
|
||||||
|
|
||||||
|
double scaleX = (double)targetWidth / source.Width;
|
||||||
|
double scaleY = (double)targetHeight / source.Height;
|
||||||
|
double scale = Math.Min(scaleX, scaleY);
|
||||||
|
|
||||||
|
// 计算实际尺寸
|
||||||
|
int actualWidth = (int)(source.Width * scale);
|
||||||
|
int actualHeight = (int)(source.Height * scale);
|
||||||
|
|
||||||
|
var resized = new Bitmap(actualWidth, actualHeight, PixelFormat.Format24bppRgb);
|
||||||
|
using (var graphics = Graphics.FromImage(resized))
|
||||||
|
{
|
||||||
|
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
|
||||||
|
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
|
||||||
|
graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
|
||||||
|
graphics.DrawImage(source, 0, 0, actualWidth, actualHeight);
|
||||||
|
}
|
||||||
|
return resized;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 调整图像大小
|
/// 调整图像大小
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user