Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

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));
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: serilog loglevel order 
Csharp :: unity change play mode color 
Csharp :: creatw list of int in C# 
Csharp :: is letter c# 
Csharp :: C#: convert array of integers to comma separated string 
Csharp :: how to create directory folder in c# 
Csharp :: wait in unity 
Csharp :: how to input a double in c# 
Csharp :: instantiate an object at a certain position unity 
Csharp :: c# check if element is last in list 
Csharp :: how to access gameobject name 
Csharp :: unity c# throw exception 
Csharp :: c# string capital first letter extension method 
Csharp :: move towards target unity 
Csharp :: Convert Newtonsoft.Json.Linq.JArray to type System.Collections.Generic 
Csharp :: c# repeat string x times 
Csharp :: unity mouse disapear 
Csharp :: unity rotate around pivot c# 
Csharp :: unity create button with parameter 
Csharp :: string to uint c# 
Csharp :: serializefield for animator 
Csharp :: get random from list c# 
Csharp :: bower azure repository tag 
Csharp :: c# null check can be simplified 
Csharp :: c# thread wait 
Csharp :: how to get desktop name in c# 
Csharp :: unity bullet script 
Csharp :: C# .net core convert int to enum 
Csharp :: cinemachine namespace not working 
Csharp :: C# int.parse input string wasnt in correct format 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =