Get Mouse location relative to picture in ImageViewer

I’m using a DesktopImageViewer, which is great. But I’m also handling MouseMove (and similar events) to allow the user to manipulate the image is some ways.

Aside from swapping it out and using a Canvas and doing all the work myself, is there a way to have the viewer control transform the x, y coordinates of the events to “picture space”?

To be clear, this is very straight-forward math when it the image is being rendered 1:1. But when scaled to fit (i.e., the control size is smaller than the image), then it gets trickier, because it’s unclear what the margins are, whether they are the same across platforms, etc. At the very least, having a read-only property like ImageDrawRect would be nice.

I would use a canvas. That puts you in control of everything. You will then need to handle scaling yourself, but you’ll have all of the information you need to do what you need.

1 Like

sub class a canvas and use drawpicture,
there you will have the picture source x,y,width,height
and the graphics drawing x,y,width,height.

scale the mouse input to 0-1 for x and y and calculate the picture x,y.

Yeah. The math is straight-forward if I used a canvas. Was just hoping the built-in image viewer had something already in place. Guess not.

Hallo Ich verwende Canvas mit Zoom-Berechnung, um meine Bilder anzuzeigen und zu vergrößern Beispiel:

https://www.dropbox.com/scl/fi/n22ya9cdwbg2qvhq2zp3x/picture-zoom-canvas.xojo_binary_project?rlkey=by1pn9tc44w9ol4b7i31r1hre&st=tlg3eua6&dl=1