My programs used to very awkwardly try to scale an image... I would try to fit it on the x-axis, then the y-axis, or else the y-axis then the x-axis, depending on the original dimensions, and also it would probably need rescaling after that scaling phase...
No more! Now I get how to scale it easily in one phase. (It seems so obvious now!)
Basically, we make sure it fits on x-axis. Then, with the updated scaling dimension, we check whether it needs further scaling on the y-axis.
The check on the x-axis is with the original width, while the check on the y-axis is with the scaled height (from scaling the x-axis to match the desired width).
When the scale is set, it is always calculated with the original width/height.
JsFiddle:
Monday, February 6, 2023
Easily scale rect to fit dimensions
Subscribe to:
Post Comments (Atom)
Coding Challenge #54 C++ int to std::string (no stringstream or to_string())
Gets a string from an integer (ejemplo gratis: 123 -> "123") Wanted to come up with my own function for this like 10 years ago ...
-
I NEEDS MY JAVASCRIPT PLEASE :) Open txtcode .txt Save as .gct Please click the blue cheat code title to activate it, a...
-
So you have a few .wbfs files from your wii game backups. You want their IDs so you can get cheats or cover art for them. Where do you find...
-
submitted for Coursera quiz. Read int's from a file, and calculate their average #include <stdio.h> int main(){ FILE *filePoi...
No comments:
Post a Comment