Android Tutorial Pinch Zoom and Move View tutorial

padvou

Active Member
Licensed User
Longtime User
I use this:
B4X:
PZ(0).Initialize(panel1,"PZ",0,1,3,1.5,False,Me)
PZ(0).LimitBorder = False
with this:
B4X:
camEx.Initialize(panel1, backCamera, Me, "Camera1")
After taking a fotograph, preview stops and panel show foto taken.
Move works fine, however zoom only zooms the panel and not the foto inside the panel.
 
Last edited:

Dominex

Active Member
Licensed User
Longtime User
This is normal, to get the effect you want you have to use the Change event, updating every time the size of the image with that of the panel.

Example:
B4X:
Sub PZ_Change (Data As LayoutData)
    image.SetLayout(Data.Left,Data.Top,Data.Width,Data.Height)
End Sub
 

padvou

Active Member
Licensed User
Longtime User
Youare right.
But, there is no image object. Panel1 is declared as I described and the goto taken is automatically shown after picturetaken event.
 

Dominex

Active Member
Licensed User
Longtime User
Strange, if the picture is "drawn" on the panel, it will change size along with the panel. If it does not, this means that the image could be placed on the panel with a immageview undeclared or similar, if so, you should identify the index of the view and resize it as for my example.
 
Last edited:

padvou

Active Member
Licensed User
Longtime User
I really appreciate you helping me with this. Although it's off-topic, could you please let me know how to identify the view's index?
 

Dominex

Active Member
Licensed User
Longtime User
It is likely that the photo is the last view in index order entered in the panel, so maybe it can work.

B4X:
Sub PZ_Change (Data As LayoutData)
    Dim v As View
    v = panel1.GetView(panel1.NumberOfViews-1)
    v.SetLayout(Data.Left,Data.Top,Data.Width,Data.Height)
End Sub
 

padvou

Active Member
Licensed User
Longtime User
It worked! However not flawlessly.
Please take a look at the attached pics.
Pic1 is 100% zoom as foto taken. Pic2 is zoomed. Notice the grey area. It's the color of the panel. The foto's view is zoomed but also displaced.
 

Attachments

  • 1.png
    309.9 KB · Views: 443
  • 2.png
    97.7 KB · Views: 490

padvou

Active Member
Licensed User
Longtime User
Success!
B4X:
Sub PZ_Change (Data As LayoutData)
    Dim v As View
    v = panel1.GetView(panel1.NumberOfViews-1)
    v.SetLayout(Data.Left-panel1.Left,Data.Top-panel1.Top,Data.Width,Data.Height)
   
End Sub
This is exactly what I was after.
Thank you very much for your efforts on the class and of course your valuable assistance!
 

slydog43

Member
Licensed User
Longtime User
any way to change the zoom sensativity, ie how much each pinch zooms the pic (I want faster zooming)
 

asales

Expert
Licensed User
Longtime User
It's possible use this class to zoom and move a label?
If yes, how I can do this?

Thanks in advance.
 

Dominex

Active Member
Licensed User
Longtime User
Yes, the class will also work with the Label.
To do this you simply need to initialize the class with the Label as well as in the example is done with the ImageView.
The content of the label along with them, you will need to resize it with the "Change" method.
 

asales

Expert
Licensed User
Longtime User
Works fine. Thanks. Simple and efficient. Great library.
 

buras3

Active Member
Licensed User
Longtime User
Hello

I set to not move
but when you zoom few times the imv moves to the left
is there any way that the imv will not move at all (zoom and unzoom from the center?
 

lymey

Active Member
Licensed User
Longtime User
[Class] Pinch Zoom and Move View
For suggestions and bug reports please do not hesitate to post it here.

Can you give me an idea on how to modify the class so that I can pinch and stretch the view rather than zooming - in other words, not retaining the aspect ratio?
 

Dominex

Active Member
Licensed User
Longtime User
Can you give me an idea on how to modify the class so that I can pinch and stretch the view rather than zooming - in other words, not retaining the aspect ratio?
It's a long time since I not program for lack of time, but you can do what you ask of course, this does not mean it's easy.

The code on lines 245 to 254 picks up the distance between your fingers when you zoom, rather than read the hypotenuse you have to read changes on the width and height.

Lines 288-307 make the zoom while maintaining the original aspect ratio, here you can zoom with the changes in the width and height without maintaining the aspect ratio.

I hope to be helped.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…