Last active
April 26, 2020 13:45
-
-
Save MRezaSafari/ba2667ace29112c50bc2fd71edda88df to your computer and use it in GitHub Desktop.
calculate the aspect ratio of image
This file contains 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
public Size CalculateAspectRation(int desiredWidth, int desiredHeight, Image image){ | |
var widthScale = (double)desiredWidth / image.Width; | |
var heightScale = (double)desiredHeight / image.Height; | |
var scale = widthScale < heightScale ? widthScale : heightScale; | |
return new Size | |
{ | |
Width = (int)(scale * image.Width), | |
Height = (int)(scale * image.Height) | |
}; | |
} |
This file contains 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
function CalculateAspectRatio(desiredWidth, desiredHeight, width, height) { | |
var widthScale = parseFloat(desiredWidth / width); | |
var heightScale = parseFloat(desiredHeight / height); | |
var scale = widthScale < heightScale ? widthScale : heightScale; | |
return { | |
Width: parseInt(scale * width), | |
Height: parseInt(scale * height) | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment