B4J Library [B4X] SD_ImageView

Discussion in 'B4J Libraries & Classes' started by Star-Dust, May 6, 2019.

  1. Star-Dust

    Star-Dust Expert Licensed User

    I created a custom ImageView view that allows you to upload an image from the web.
    Just pass the URL as a parameter
    This class is B4X but does not depend on the XUI library


    Author: Star-Dust
    Version: 0.02
    • SD_ImageView
      • Events:
        • LongClick
        • OneClick
      • Fields:
        • NatObject As ImageView
        • Zoom As ImageView
      • Functions:
        • BringToFront
        • DesignerCreateView (Base As Panel, Lbl As Label, Props As Map)
        • GetBase
        • Initialize (Callback As Object, EventName As String)
        • RemoveViewFromParent
        • RequestFocus
        • SendToBack
      • Properties:
        • Bitmap As Bitmap [write only]
        • Enable As Boolean [write only]
        • Gravity As Int [write only]
        • Height As Float [write only]
        • Left As Float [write only]
        • PreserveRatio As Boolean [write only]
        • Tag As Object [write only]
        • Top As Float [write only]
        • UrlBitmap As String [write only]
        • Visible As Boolean [write only]
        • Width As Float [write only]

    Sub Globals
    'These global variables will be redeclared each time the activity is created.
        'These variables can only be accessed from this module.
        Private SD_ImageView1 As SD_ImageView
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    End Sub

    Sub SD_ImageView1_OneClick
    End Sub

    Sub SD_ImageView1_LongClick
    End Sub

    Attached Files:

    Last edited: May 8, 2019
  2. Almora

    Almora Active Member Licensed User

    Can zoom feature be added?
  3. Star-Dust

    Star-Dust Expert Licensed User

    What kind of zoom do you want to get?
    Enlarge the view?
    Enlarge a coordinate from code?
    Enlarge with pinch to zoom?
    Last edited: May 7, 2019
  4. Almora

    Almora Active Member Licensed User

    As in webview
    pinch ti zoom
  5. Star-Dust

    Star-Dust Expert Licensed User

    It could be done, we'll see at the next update
    Almora and Johan Hormaza like this.
  6. Star-Dust

    Star-Dust Expert Licensed User

    Fixed a bugs in the manifest. Updated to post#1
    DonManfred, Erel and José J. Aguilar like this.
  7. Star-Dust

    Star-Dust Expert Licensed User

    Update rel 0.02
    Add Pinch to Zoom
    Gravity.FILL ' Only Android

    It's not perfect but it works. Besides, I can't do everything :p

    PS. Obviously it only works on Android and iOs the zoom and it doesn't work for desktop. There are no mice that click at two different points :D:D:D
    Last edited: May 8, 2019
  8. max123

    max123 Active Member Licensed User

    @Star-Dust I've found a mistake on B4J sample, SD_ImageView line 216 'zm' assigned before a declaration, so I added this line on Class_Globals under B4J conditionals and it now compile and runs well:

    Private zm As Boolean = False   ' Added this line
    The full Class_Globals:
    Sub Class_Globals
    Private mEventName As String 'ignore
        Private mCallBack As Object 'ignore
    ' Zoom
        #IF B4A
    Private mBase As Panel
    Public NatObject As ImageView
    Private zm As Boolean = False
    Private StartX,StartY,LastX,LastY As Int
    Private Wd,Ht As Int
    Private PointerStartID=-1,PointerLastID=-1 As Int
    #ELSE IF B4I
    Private mBase As Panel
    Public NatObject As ImageView
    Private Multi As Panel
    Private zm As Boolean = False
    Private Wd,Ht As Int
    Private NativeMe As NativeObject
    Private fingers As Map
    Type FingerData (StartX As Float, StartY As Float,LastX As Float, LastY As Float)
    Private Lastclick As Long = -1
    #ELSE IF B4J
    Private mBase As Pane
    Public NatObject As ImageView
    Private zm As Boolean = False   ' Added this line
        #END IF
    End Sub
    This is a power of zipped libraries, not protected but exposes code and all files, if the user find a bug, just open a library zip (I open with 7zip or WinRar) and correct the bug.

    Also I had to enlarge on the designer the custom view because is too small, on B4A you used Gravity.Fill but on B4J the image is larger than the custom view and do not resize.

    Finally the zoom is possible even on B4J? I know that desktop has no gestures, so pinch to zoom as Android, but it is possible to change the zoom by code? Even is very good have a zoom with mouse whell, is that possible? You can add it?

    I think this help you, many thanks for this library.
    Last edited: Sep 7, 2019
  9. max123

    max123 Active Member Licensed User

    Sorry, for resize my mistake, I've managed it with designer and added a button to grab a picture, now the image resize when load . ;)
    But for 'zm' seem to be a typo.

    I will try your library to grab ESP32-CAM camera module as you suggested on this forum.

    SD_ImageView1.UrlBitmap = ""   ' Station mode
    SD_ImageView1.UrlBitmap = ""      ' Access Point mode
    Many thanks
    Last edited: Sep 7, 2019
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice