Created
March 12, 2015 13:00
-
-
Save IUnknown68/b32bc4c7b351b9d579f4 to your computer and use it in GitHub Desktop.
Constrain image size
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
bool ConstrainImageSize( | |
int &aWidth, // in/out - actual image width | |
int &aHeight, // in/out - actual image height | |
const int aMaxWidth, // in - max width | |
const int aMaxHeight // in - max height | |
) const | |
{ | |
float ratioNeed = std::max( (float)aWidth / (float)aMaxWidth, (float)aHeight / (float)aMaxHeight ); | |
if( ratioNeed > 1.0 ) { | |
// actually needs downscaling at all | |
aWidth = (int)((float)aWidth / ratioNeed + 0.5); | |
aHeight = (int)((float)aHeight /ratioNeed + 0.5); | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment