If your height & width are integers, you can just do this...
height = height * (int)(scaleFactor*100) / 100;
width = width * (int)(scaleFactor*100) / 100;
Alternatively, this solution also works for int
but makes more sense with floating point vars...
height = floor(height * scaleFactor);
width = floor(width * scaleFactor);
Or, regardless of the variable types, you can just let the compiler worry about how to handle the rounding...
height = height * scaleFactor;
width = width * scaleFactor;
...but with that solution, you may get off-by-1 rounding errors from one platform to the next. That may not matter in your use case, though.
Another possibility, if your scaleFactor
is itself an int
and (in this example) is 30%, then scaleFactor
could be the value 30
, and you'd simply do this...
height = height * scaleFactor / 100;
width = width * scaleFactor / 100;
The key is that if you scale both your x & y coordinates by the same factor, you preserve the original aspect ratio.