Created
October 14, 2020 08:53
-
-
Save unitycoder/6999e19a1af0f78883fb1ebf44ed3a1e to your computer and use it in GitHub Desktop.
Calculate resize with aspect ratio (scale)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //// get aspect ratio https://stackoverflow.com/a/32593158/5452781 | |
| int sourceWidth = 3000; | |
| int sourceHeight = 2000; | |
| int targetWidth = 1920; | |
| int targetHeight = 1080; | |
| float percent = (new List<float> { (float)targetWidth / (float)sourceWidth, (float)targetHeight / (float)sourceHeight }).Min(); | |
| Size resultSize = new Size((int)Math.Floor(sourceWidth * percent), (int)Math.Floor(sourceHeight * percent)); | |
| Console.WriteLine("size= " + sourceWidth + "x" + sourceHeight + " percent= " + percent + " result=" + (sourceWidth * percent) + "x" + (sourceHeight * percent)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment