Image resizing and round-off problem
in
Programming Questions
•
3 years ago
Let me focus on width, but it's the same for height of course. Suppose I have a sketch window and image size that are both 600 pixels wide. Now I want to resize the image to put it on the screen multiple times. My problem is that in some cases there will be rounding off, which in turn will result in not perfectly filling the screen! Some examples...
img.resize(width/2, 0) => 300 pixels, fits perfectly on the screen 2 times
img.resize(width/4, 0) => 150 pixels, fits perfectly on the screen 4 times
img.resize(width/7, 0) => 85,714 will become probably 85 pixels and result in 'missing width'
I'd rather not be limited to only the divisions that result in whole numbers...
...and I understand having 0,714 pixel sizes is a challenge as well
So how to solve this?
img.resize(width/2, 0) => 300 pixels, fits perfectly on the screen 2 times
img.resize(width/4, 0) => 150 pixels, fits perfectly on the screen 4 times
img.resize(width/7, 0) => 85,714 will become probably 85 pixels and result in 'missing width'
I'd rather not be limited to only the divisions that result in whole numbers...
...and I understand having 0,714 pixel sizes is a challenge as well
So how to solve this?
1
