B4J Question B4J Pan ImageView

js486dog

Active Member
Licensed User
I would like to pan image loaded into the ImageView.
ImageView1 is parent P_map Pane.

I have attached my project.
My Pan ImageView code is below, but I need to help to amend it.
Code is not as to has to be.
If someone know solution, please give advice.

My code:
B4X:
Sub P_map_MouseDragged (EventData As MouseEvent)
    ox =  EventData.X
    oy =  EventData.Y
    
    If ox < zox Then
        ImageView1.Left = ImageView1.Left - 3
    Else If ox > zox Then
        ImageView1.Left = ImageView1.Left + 3
Else If ox = zox Then
    ImageView1.Left = ImageView1.Left
    End If
    
    If oy < zoy Then
        ImageView1.Top = ImageView1.Top - 3
    Else If oy > zoy Then
        ImageView1.Top = ImageView1.Top + 3
Else If oy = zoy Then
    ImageView1.Top = ImageView1.Top
    End If
End Sub

Sub P_map_MousePressed (EventData As MouseEvent)
    zox =  EventData.X
    zoy = EventData.Y
End Sub
 

Attachments

  • Image_View.zip
    10.4 KB · Views: 90

js486dog

Active Member
Licensed User
See this.

mouse whell
drag
Thank you very much "oparra" for the answer.
Your code with ZoomImageView is great, but I miss "EventData" (at least MouseMoved).

Classic ImageView has "EventData" (MouseMoved, MouseDragged ...).
B4X:
Sub ImageView1_MouseMoved (EventData As MouseEvent)
    L_xsur_pix = EventData.X
    L_ysur_pix = EventData.Y
End Sub
 
Upvote 0

js486dog

Active Member
Licensed User
See this.

mouse whell
drag
Hi "oparra".

After night deep sleep I understand at last how your code works.
Thank you again for your advice.
I have attached the project with pan and zoom.

Maybe like this:
B4X:
Sub P_map_MousePressed (EventData As MouseEvent)
    StartLeft = ImageView1.Left
    StartTop = ImageView1.Top
    StartX = EventData.X
    StartY = EventData.Y
End Sub

Sub P_map_MouseDragged (EventData As MouseEvent)
    ImageView1.Left = Min(0.5 * P_map.Width, StartLeft + 1.2 * (EventData.X - StartX))
    ImageView1.Left = Max(-(ImageView1.Width - 0.5 * P_map.Width), ImageView1.Left)
    ImageView1.Top = Min(0.5 * P_map.Height, StartTop + 1.2 * (EventData.Y - StartY))
    ImageView1.Top = Max(-(ImageView1.Height - 0.5 * P_map.Height), ImageView1.Top)
End Sub
 

Attachments

  • Image_View_pan_zoom.zip
    12.4 KB · Views: 101
Last edited:
Upvote 0
Top