Android Question Know coordinates of image clicked in ZoomImageView

vecino

Well-Known Member
Licensed User
Longtime User
Hi, see if you can give me a hand.
I'm trying to know at which position (x,y) an image loaded in a ZoomImageView was clicked (tapped).
I have managed to get the x,y positions of the view pane, but what I need is the x,y position of the image loaded into it.
Thank you very much.
 

vecino

Well-Known Member
Licensed User
Longtime User
Hi, I just edited the code of ZoomImageView.pas and added a couple of public variables.
Thank you.

B4X:
Private Sub pnl_Touch (Action As Int, X1 As Float, Y1 As Float)
    If Action = pnl.TOUCH_ACTION_DOWN Or TouchDown = False Then
        StartLeft = pnlBackground.Left
        StartTop = pnlBackground.Top
        StartX = X1
        StartY = Y1
        TouchDown = True
        If xui.IsB4A = False Then ClickStart = DateTime.Now
    Else If Action = pnl.TOUCH_ACTION_MOVE And TouchDown Then
        pnlBackground.Left = Min(0.5 * mBase.Width, StartLeft + 1.2 * (X1 - StartX))
        pnlBackground.Left = Max(-(pnlBackground.Width - 0.5 * mBase.Width), pnlBackground.Left)
        pnlBackground.Top = Min(0.5 * mBase.Height, StartTop + 1.2 * (Y1 - StartY))
        pnlBackground.Top = Max(-(pnlBackground.Height - 0.5 * mBase.Height), pnlBackground.Top)
        SetImageViewLayout
    Else if Action = pnl.TOUCH_ACTION_UP Then
        TouchDown = False
        If DateTime.Now - ClickStart < ClickThreshold And DisableClickEvent = False Then
            If xui.SubExists(mCallBack, mEventName & "_Click", 0) Then
            
                iX = X1   ' <---
                iY = Y1   ' <---
            
                CallSub(mCallBack, mEventName & "_Click")
            End If
        End If
    Else
        'Log("touch cancelled")
    End If
End Sub
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Of course it is possible. You need to understand how ZoomImageView handles the panning and zooming and then find the coordinate.
??? ... in that case I wouldn't have asked.

Well, I'll keep trying ?
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
check that this can help you:
Note:
See the canvas trick to capture image coordinates
 
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Hello, thank you for your help.
I know how to extract the image coordinate, what I don't know (and that's the problem) is how to implement it to ZoomImageView.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
Hello, thank you for your help.
I know how to extract the image coordinate, what I don't know (and that's the problem) is how to implement it to ZoomImageView.
is what I'm trying to tell you, not only the coordinates will be helpful.
Of course it is possible. You need to understand how ZoomImageView handles the panning and zooming and then find the coordinate.
see:

Note:
your example only captures the coordinates of a still image with a given zoom.
You don't just have to capture the coordinates.
You have to get other additional data like projection, zoom (scale), etc.
 
Last edited:
Upvote 0

vecino

Well-Known Member
Licensed User
Longtime User
Thank you, oparra, I appreciate your help, I have been looking at the source code you have linked, but it is too complicated for my knowledge on the subject.
I'm going to keep looking at that code, and see if I can figure it out.
 
Upvote 0
Top