We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm trying to resize an image so that it fits my sketch-size and because I need it to work for any picture in any size I will have to use this formula: widthOfImage/heightOfImage = difference
and later: difference * newWidthOfImage
But when I say image.width/image.height
I get an int in return. Which makes the result very inaccurate especially when the difference is around 1.
Why is that and can I fix it? or work around it?
Thanks in advance :)
Answers
If I understand your problem correctly, there are no "fractional pixels" in a display. Their x, y coordinates are integers so rounding is necessary. I don't know of any way to apply an image with a fractional component to a screen display.
Ok, as I expected the problem occurs because the numbers I'm dividing are both integers, so the result is also an integer, at least according to GoToLoop in this discussion: https://forum.processing.org/two/discussion/13417/problem-with-making-a-window-size-scale#latest
He says it's possible to force a floating point value by making one of them a float, so I can actually just do this:
float iwidth = image.width;
and use "iwidth" in the equation.It will still round however when the image is displayed as it still maps to an integer space. So, if the display error is acceptable that's cool.