Scaling an image with the mouse wheel, around the mouse coordinates

I would like to be able to point the mouse to a part of an image in a canvas that’s scaled down to fit the canvas, then zoom in on that part of the image with the mouse wheel. I have the mouse wheel part working, but the behavior I want is for the image to scale around the position where the mouse arrow is located.

So I need to get the location of the mouse relative to the image inside the canvas, not the canvas origin. If we’re zoomed in on the image a bit, the origin of the image would be in the negative, and the image would be cropped inside the smaller canvas.

Is there an easy way to get my mouse coordinates relative to the image?

Hello Perry
some things you should think about for yourself and not ask others for a solution

here still the extension

Window 10
the live view is not so well possible with window
A new image build-up is only carried out after releasing the mouse button
this is where XOJO differentiates between the systems

Thanks for the link, but I don’t see an example of what I’m looking for in there - maybe I’m missing it because a lot of your code is in German, which I don’t speak, so it’s hard for me to follow. It’s not clear to me how your app does what I’m looking to do: scale the image around the arrow position, using the mouse scroll wheel. All I need to do is find the X,Y coordinates of the mouse on the image, not within the canvas, since the image might spill past the canvas bounds. I can figure it out from there.

I’m not using the mouse button. This is about using the mouse wheel to zoom the image in and out, while keeping the pixels that are under the arrow, under the arrow. The image refreshes when you stop scrolling the mouse wheel, so if you go slowly it’s a bit like a live scroll. If you go fast, it should just zoom in to that zoom factor at the specified location (the X,Y coordinates) of the underlying image.

Seriously? This is a forum. It’s about sharing ideas and asking for help. I’m not a programmer by trade, I do this on the side while also doing my day job, so if I can copy and paste a code snippet in a few minutes, vs spending an hour or more puzzling through a problem, I’m absolutely fine with that. I appreciate the help, but there’s no need to berate someone who is asking a question. The whole point of Xojo is that it’s a rapid application development tool, actively marketed towards people like me, and there is a substantial ecosystem of plugins and code snippets out there for it, which I rely on to get things done, well, rapidly. It’s kind of the point of Xojo, really.

1 Like

This is a forum to ask advice surely?


This is the behavior I’m after:

I have a Canvas subclass that does exactly that. But lots of the code is deprecated.

I will check and write back.


Cool - thanks. I’d love to take a look at it if still works!