Created
December 26, 2018 19:49
-
-
Save jvcleave/c44c57a2bd84f14959b071fa5532c1dc to your computer and use it in GitHub Desktop.
aspect ratio
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
static ofVec2f getFitAspectRatioSize(float maxWidth, float maxHeight, float imgWidth, float imgHeight) | |
{ | |
ofVec2f result; | |
float widthRatio = maxWidth / imgWidth; | |
float heightRatio = maxHeight / imgHeight; | |
float bestRatio = min(widthRatio, heightRatio); | |
result.x = imgWidth * bestRatio; | |
result.y = imgHeight * bestRatio; | |
return result; | |
} | |
static ofVec2f getFitAspectRatioSize(ofVec2f windowSize, float imgWidth, float imgHeight) | |
{ | |
return getFitAspectRatioSize(windowSize.x, windowSize.y, imgWidth, imgHeight); | |
} | |
static ofVec2f getFitAspectRatioSize(ofVec2f windowSize, ofImage& image) | |
{ | |
return getFitAspectRatioSize(windowSize, image.getWidth(), image.getHeight()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment