B4A Library Zoomage - A simple pinch-to-zoom Library

Similar threads

B4A Library PDFium - Pdfview2
B4A Library IPCamView
B4A Library msEmoji V1.0.0
B4A Library CreditsRollView V1.0.0
B4A Library VRCalendarView

DonManfred

Expert
Licensed User
This is a shortwrap for this Github-Project.

Notes:
- The Apps needs to be AppCompat compatible as the Zoomage extends an AppCompat Imageview
- The Image should be place in a path readable by the app. It seems not to work with Assets. I did not tried it much; if i copy it first to a save path it works for me.

zoomage

Author:
Version: 0.1
  • ZoomageView
    • Fields:
      • ba As BA
    • Functions:
      • BringToFront
      • DesignerCreateView (base As Panel, lw As Label, props As Map)
      • Initialize (EventName As String)
      • Invalidate
      • Invalidate2 (arg0 As android.graphics.Rect)
      • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
      • IsInitialized As Boolean
      • RemoveView
      • RequestFocus As Boolean
      • reset
        Reset image back to its original size. Will snap back to original size
        if animation on reset is disabled via {@link #setAnimateOnReset(boolean)}.
      • reset2 (animate As Boolean)
        Reset image back to its starting size. If {@code animate} is false, image
        will snap back to its original size.
        animate: animate the image back to its starting size
      • SendToBack
      • SetBackgroundImage (arg0 As android.graphics.Bitmap) As BitmapDrawable
      • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
      • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
      • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
      • setScaleRange (minScale As Float, maxScale As Float)
        Set the minimum and maximum allowed scale for zooming. {@code minScale} cannot
        be greater than {@code maxScale} and neither can be 0 or less. This will result
        in an {@link IllegalStateException}.
        minScale: minimum allowed scale
        maxScale: maximum allowed scale
      • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    • Properties:
      • AnimateOnReset As Boolean
        Returns status of animateOnReset. This causes the image to smoothly animate back
        to its start position when reset. Default value is true.
      • AutoCenter As Boolean
        Whether or not the image should automatically center itself when it's dragged partially or
        fully out of view.
      • AutoResetMode As Int
        Get the current {@link AutoResetMode} mode of the image. Default value is {@link AutoResetMode#UNDER}.
      • Background As android.graphics.drawable.Drawable
      • Color As Int [write only]
      • CurrentScaleFactor As Float [read only]
        Get the current scale factor of the image, in relation to its starting size.
      • DoubleTapToZoom As Boolean
        Gets double tap to zoom state.
      • DoubleTapToZoomScaleFactor As Float
        Gets the double tap to zoom scale factor.
      • Enabled As Boolean
      • Height As Int
      • ImageBitmap As android.graphics.Bitmap [write only]
      • ImageDrawable As android.graphics.drawable.Drawable [write only]
      • ImageURI As String [write only]
        {@inheritDoc}
      • Left As Int
      • Padding As Int()
      • Parent As Object [read only]
      • RestrictBounds As Boolean
        If restricted bounds are enabled, the image will not be allowed to translate
        farther inward than the edges of the view's bounds, unless the corresponding
        dimension (width or height) is smaller than those of the view's frame.
      • Tag As Object
      • Top As Int
      • Translatable As Boolean
        Returns whether the image is translatable.
      • Visible As Boolean
      • Width As Int
      • Zoomable As Boolean
        Returns the zoomable state of the image.

An Example can be downloaded HERE due to it´s size.
 

Attachments

Mahares

Well Known Member
Licensed User
The Image should be place in a path readable by the app. It seems not to work with Assets. I did not tried it much; if i copy it first to a save path it works for
You did a really good job with this lib. You documented everything well. I was able to use the Assets folder as shown in my below code without having to save the file from assets to defaultExternal. It works well. I can zoom in and out. If, what I did does not make sense, please correct accordingly:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout1")  
    Dim bd As BitmapDrawable
    bd.Initialize(LoadBitmap(File.DirAssets, "empire.jpg"))
    bd.Gravity = Gravity.FILL
    ZoomageView1.ImageDrawable=bd
    ZoomageView1.setScaleRange(1,4)
End Sub
 

Mahares

Well Known Member
Licensed User
It seems not to work with Assets
Here is another way of achieving the same result as above without having to save the bitmap file to DefaultExternal, even shorter than the one in post #11:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout1")   
    ZoomageView1.ImageBitmap=LoadBitmap(File.DirAssets, "empire.jpg")   
    ZoomageView1.setScaleRange(1,4)
End Sub
 
Top