Getting Image coordinates when image is zoomed
-
Does anyone have a code snippet that shows how to get a clicked point on a zoomed graphic that corresponds to the same point on the unzoomed graphic?
-
Does anyone have a code snippet that shows how to get a clicked point on a zoomed graphic that corresponds to the same point on the unzoomed graphic?
Hint , start out by making a function like this : Function ScalePointAToPointOnLineB(PointOnLineA , LengthLineA , LengthLineB) And use this trick wisely..
Jarno Burger Video Jockey
-
Hint , start out by making a function like this : Function ScalePointAToPointOnLineB(PointOnLineA , LengthLineA , LengthLineB) And use this trick wisely..
Jarno Burger Video Jockey
Thanks for your reply. I have a 42MB image in a user control that is scrollable, and capable of being zoomed out and in. If I click on the image when it is not zoomed I can get the coordinates of the clicked point. The problem is when I zoom in the device coordinates of course change when I click on the exact same spot on the graphic. I know I need to transform a matrix but I don't have much experience with this particular transformation. I would lke to be able to get the same coordinates of the image no matter if it is zoomed in or not, or scrolled. Any ideas regarding matrix transformation using the points.
-
Thanks for your reply. I have a 42MB image in a user control that is scrollable, and capable of being zoomed out and in. If I click on the image when it is not zoomed I can get the coordinates of the clicked point. The problem is when I zoom in the device coordinates of course change when I click on the exact same spot on the graphic. I know I need to transform a matrix but I don't have much experience with this particular transformation. I would lke to be able to get the same coordinates of the image no matter if it is zoomed in or not, or scrolled. Any ideas regarding matrix transformation using the points.
Maybe your zoom could be more like a growing/shrinking rectangle instead of a double var ? Then you could easily find mouse-position relative to your zoom-rectangle. Then find your zoom-rectangle back in your pic in memory , and you'll have the pixel position. But you could do this in 10 / 15 ways , all depends what you like yourself most. But stick to the rectangles in rectangles concept, and only your mouse position as a position (relative to a rectangle to a reactangle to a rectangle to a rectangle etc...). You'll need that later on , for other drawing stuff too.. Also , using default scrollbar behaviour to scroll a picture to left / right / up / down , first looks like a nice and easy idea. But you'll end up writing patched stuff to let those scrollbars do what you want , when zoomed or something like that. First dump the scrollbars. Try to build a drag (with middle mousebutton) first , or use arrow/+/- keys or something. Just for the learning experience.
Jarno Burger Video Jockey
-
Maybe your zoom could be more like a growing/shrinking rectangle instead of a double var ? Then you could easily find mouse-position relative to your zoom-rectangle. Then find your zoom-rectangle back in your pic in memory , and you'll have the pixel position. But you could do this in 10 / 15 ways , all depends what you like yourself most. But stick to the rectangles in rectangles concept, and only your mouse position as a position (relative to a rectangle to a reactangle to a rectangle to a rectangle etc...). You'll need that later on , for other drawing stuff too.. Also , using default scrollbar behaviour to scroll a picture to left / right / up / down , first looks like a nice and easy idea. But you'll end up writing patched stuff to let those scrollbars do what you want , when zoomed or something like that. First dump the scrollbars. Try to build a drag (with middle mousebutton) first , or use arrow/+/- keys or something. Just for the learning experience.
Jarno Burger Video Jockey
Well I dumped the scroll bars and have a panning aspect to scroll - I can pan the graphic and get the proper image coordinates. I have the scale of the horizontal and vertical. I can zoom in and out in many levels at increments of about 10%. As soon as I zoom in the coordinates of course change as they should. But I need the to be able to click the graphic at the exact same spot when zoomed in and receive the same coordinate of the exact same spot when not zoomed in. Here's what I have: scaleX = CSng(Me.GetScreenRect.Width()) / Me.Width() scaleY = CSng(Me.GetScreenRect.Height()) / Me.Height() x = CInt(Math.Round(mouseXY.X * scaleX)) y = CInt(Math.Round(mouseXY.Y * scaleY)) Works fine when not zoomed in. I need the math that would allow for obtaining the same clicked spot while zoomed.
-
Well I dumped the scroll bars and have a panning aspect to scroll - I can pan the graphic and get the proper image coordinates. I have the scale of the horizontal and vertical. I can zoom in and out in many levels at increments of about 10%. As soon as I zoom in the coordinates of course change as they should. But I need the to be able to click the graphic at the exact same spot when zoomed in and receive the same coordinate of the exact same spot when not zoomed in. Here's what I have: scaleX = CSng(Me.GetScreenRect.Width()) / Me.Width() scaleY = CSng(Me.GetScreenRect.Height()) / Me.Height() x = CInt(Math.Round(mouseXY.X * scaleX)) y = CInt(Math.Round(mouseXY.Y * scaleY)) Works fine when not zoomed in. I need the math that would allow for obtaining the same clicked spot while zoomed.
-
do you have any control, that you set your zoom level with? You need to get the value of it and use it to compute back your coorinates. Regards: Didi
Yes. The mousewheel zooms the image in and out. So if i'm in 10% just reverse the the scale value from 1.1 to .9?
-
Yes. The mousewheel zooms the image in and out. So if i'm in 10% just reverse the the scale value from 1.1 to .9?