Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Getting Image coordinates when image is zoomed

Getting Image coordinates when image is zoomed

Scheduled Pinned Locked Moved Visual Basic
tutorialquestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alan Streisel
    wrote on last edited by
    #1

    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?

    J 1 Reply Last reply
    0
    • A Alan Streisel

      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?

      J Offline
      J Offline
      Jarno Burger
      wrote on last edited by
      #2

      Hint , start out by making a function like this : Function ScalePointAToPointOnLineB(PointOnLineA , LengthLineA , LengthLineB) And use this trick wisely..

      Jarno Burger Video Jockey

      A 1 Reply Last reply
      0
      • J Jarno Burger

        Hint , start out by making a function like this : Function ScalePointAToPointOnLineB(PointOnLineA , LengthLineA , LengthLineB) And use this trick wisely..

        Jarno Burger Video Jockey

        A Offline
        A Offline
        Alan Streisel
        wrote on last edited by
        #3

        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.

        J 1 Reply Last reply
        0
        • A Alan Streisel

          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.

          J Offline
          J Offline
          Jarno Burger
          wrote on last edited by
          #4

          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

          A 1 Reply Last reply
          0
          • J Jarno Burger

            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

            A Offline
            A Offline
            Alan Streisel
            wrote on last edited by
            #5

            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.

            D 1 Reply Last reply
            0
            • A Alan Streisel

              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.

              D Offline
              D Offline
              DidiKunz
              wrote on last edited by
              #6

              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

              A 1 Reply Last reply
              0
              • D DidiKunz

                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

                A Offline
                A Offline
                Alan Streisel
                wrote on last edited by
                #7

                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?

                D 1 Reply Last reply
                0
                • A Alan Streisel

                  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?

                  D Offline
                  D Offline
                  DidiKunz
                  wrote on last edited by
                  #8

                  why not? Just try it out, if it's accurate, I think it should. Regards: Didi

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups