Answers for "c# resize image keep aspect ratio"

C#
2

c# resize image keep aspect ratio

using System.Drawing;
public static Size ResizeKeepAspect(this Size src, int maxWidth, int maxHeight, bool enlarge = false)
{
    maxWidth = enlarge ? maxWidth : Math.Min(maxWidth, src.Width);
    maxHeight = enlarge ? maxHeight : Math.Min(maxHeight, src.Height);

    decimal rnd = Math.Min(maxWidth / (decimal)src.Width, maxHeight / (decimal)src.Height);
    return new Size((int)Math.Round(src.Width * rnd), (int)Math.Round(src.Height * rnd));
}
Posted by: Guest on April-23-2020

Code answers related to "c# resize image keep aspect ratio"

C# Answers by Framework

Browse Popular Code Answers by Language