I'm really struggling with getting a pixel coordinate from an ImageView click event (with preserve ratio enabled). Without preserving the ratio and scaling to fit it is trivial. But I would prefer to scale the image to fit while preserving the ratio.
Lets say the ImageView is 500x500, and the source image is 400x400. The ImageView will scale it to 500x500 to fill the image and you can easily surmise the pixel coordinate from the event coordinate.
If the ratio of the image doesn't match the ImageViews' then that is where I am struggling. I have tried figuring the aspect ratio of both the image and ImageView then calculating the scale for each axis, but I fail to do it correctly every time. Maybe I am overthinking something. Is there an elegant way to do this?
I am trying to overlay a base image with a canvas that I am able to draw onto but the base images vary in size. Some can be small and others are very large. So instead of changing the window size to match I would like to handle it by scaling the image down. I don't think this problem is unique to B4J, I don't think I know how to do it anywhere.
Hope this makes sense, thank you for reading
Lets say the ImageView is 500x500, and the source image is 400x400. The ImageView will scale it to 500x500 to fill the image and you can easily surmise the pixel coordinate from the event coordinate.
If the ratio of the image doesn't match the ImageViews' then that is where I am struggling. I have tried figuring the aspect ratio of both the image and ImageView then calculating the scale for each axis, but I fail to do it correctly every time. Maybe I am overthinking something. Is there an elegant way to do this?
I am trying to overlay a base image with a canvas that I am able to draw onto but the base images vary in size. Some can be small and others are very large. So instead of changing the window size to match I would like to handle it by scaling the image down. I don't think this problem is unique to B4J, I don't think I know how to do it anywhere.
Hope this makes sense, thank you for reading