B4J Library [B4X] SD_ImageView

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

NOTE: You can use this library for personal and commercial use. Include it in your projects.. Attention, even if it is a B4XLib library, it is not allowed to decompress it, modify it, change its name or redistribute it without the permission of the author

SD_ImageView

Author
: Star-Dust
Version: 0.03

  • SD_ImageView
    • Events:
      • LongClick
      • OneClick
    • Fields:

      • NatObject As ImageView
      • Zoom As Boolean
    • 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]

SAMPLE
B4X:
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:
    Activity.LoadLayout("Layout1")
    Sleep(1000)
    SD_ImageView1.Gravity=Gravity.FILL
    SD_ImageView1.UrlBitmap="https://b4x-4c17.kxcdn.com/android/forum/data/avatars/l/0/1.jpg?1469350209"
End Sub

Sub SD_ImageView1_OneClick

End Sub

Sub SD_ImageView1_LongClick

End Sub
ok.png
 

Attachments

  • aSample.zip
    9.1 KB · Views: 651
  • jSample.zip
    2 KB · Views: 614
  • iSample.zip
    2.4 KB · Views: 518
  • SD_ImageView.b4xlib
    3.2 KB · Views: 544
Last edited:

Star-Dust

Expert
Licensed User
Longtime 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:

Star-Dust

Expert
Licensed User
Longtime User
It could be done, we'll see at the next update
 

Star-Dust

Expert
Licensed User
Longtime User
Update rel 0.02
Add Pinch to Zoom
B4X:
SD_ImageView1.Zoom=True
SD_ImageView1.Gravity=Gravity.FILL ' Only Android
SD_ImageView1.UrlBitmap="https://b4x-4c17.kxcdn.com/android/forum/data/avatars/l/0/1.jpg?1469350209"
Video1.gif


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:

max123

Well-Known Member
Licensed User
Longtime 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:

B4X:
Private zm As Boolean = False   ' Added this line

The full Class_Globals:
B4X:
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:

max123

Well-Known Member
Licensed User
Longtime User
Sorry, for resize my mistake, I've managed it with designer and added a button to grab a picture, now the image resizes 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.

B4X:
SD_ImageView1.UrlBitmap = "http://192.168.178.20/jpg"   ' Station mode
SD_ImageView1.UrlBitmap = "http://192.168.4.1/jpg"      ' Access Point mode

Many thanks
 
Last edited:

hdtvirl

Active Member
Licensed User
Longtime User
Hi, I tried your code on B4J and I am still getting the error SD_ImageView line 216 'zm' assigned before a declaration, I get this even in a new project with just the SD_imageView library loaded.

Did anybody manage to get it to work?

Regards

hdtvirl
 

max123

Well-Known Member
Licensed User
Longtime User
Hi @Star-Dust , I know you want to call the class with your name, but because you just don't call it WebImageView, so it is more quickly to understand?

I've developed 12 libraries to release on next months when I tested a lots and removed any minor bug, none of this starts with my name letters, to mantain alphabetical order in the Library tab I just call it with Class prefix, eg ClassLed, ClassSlider etc... not very elegant because these are not just Classes but compiled to library, but more readable in the library tab instead to insert library author name.

Many thanks for your work ;)
 
Last edited:

max123

Well-Known Member
Licensed User
Longtime User
@hdtvirl please read my reply #8 and #9, 'zm' still missed, not declared at all, I've added it manually inside the zipped library and now it compile and execute ;)

Even I do not received any reply to my questions and the problem not solved so other users have the same problem... Very good support :oops:

Have a good day
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
UPDATE 0.03
Fix Bugs
 

max123

Well-Known Member
Licensed User
Longtime User
Many thanks @Star-Dust ;)

Please change the library name to WebImageView, not for me, I alredy changed it, for other users ?
This is more intuitive.

Thank you
 

Star-Dust

Expert
Licensed User
Longtime 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:

B4X:
Private zm As Boolean = False   ' Added this line

The full Class_Globals:
B4X:
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.
No enlargement is expected for B4J and will not be added. It is a free library that I made for my pastime, there will be no future development.
 

Star-Dust

Expert
Licensed User
Longtime User
Hi @Star-Dust , I know you want to call the class with your name, but because you just don't call it WebImageView, so it is more quickly to understand?

I've developed 12 libraries to release on next months when I tested a lots and removed any minor bug, none of this starts with my name letters, to mantain alphabetical order in the Library tab I just call it with Class prefix, eg ClassLed, ClassSlider etc... not very elegant because these are not just Classes but compiled to library, but more readable in the library tab instead to insert library author name.

Many thanks for your work ;)
I'm really glad you're a very prolific developer. I understand your choice of giving names as you see fit, and surely in developing your classes you have had to make choices that are based on your evaluations and your experiences as a developer.

I also do the same, I reserve the right to make the choices of the classes I develop. So the names chosen reflect a fundamental requirement, I like them.

I am sure that if you also make a bookshop similar to mine, you will want to choose the name you think is most suitable.

PS. This Library is not an extension of the WebWiev, but an exemption from the Image class. This is why it bears the name ImageView, and for the same reason it does not have the integrated Zoom as a webView would have it, but I create it with the Touch event.
 

Star-Dust

Expert
Licensed User
Longtime User
@hdtvirl please read my reply #8 and #9, 'zm' still missed, not declared at all, I've added it manually inside the zipped library and now it compile and execute ;)

Even I do not received any reply to my questions and the problem not solved so other users have the same problem... Very good support :oops:

Have a good day
Many thanks @Star-Dust ;)

Please change the library name to WebImageView, not for me, I alredy changed it, for other users ?
This is more intuitive.

Thank you
In this forum there are Free and other libraries that are released with a donation.

My free libraries are actually projects that I create for myself and sometimes I share them with others thinking that they can be useful.
For this reason I do not guarantee assistance, it is not a product you have purchased, therefore there must be no claim. But when I have time I am happy to help others. I like to share.

As for the name, although it is possible to edit the ZIP file, it would be nice and respectful to leave the libraries as I created them. I didn't authorize the change.

One of the reasons why I no longer publish B4XLib libraries is precisely this, the other developers feel authorized to modify my work without asking.
 

max123

Well-Known Member
Licensed User
Longtime User
I changed it's name just for me because help to find it on the Library Tab. I do not redestribuite it with changed name, so I don't know what is the problem :oops:

I just wanted to give some advice and I'm sorry you took it as an offensive, that's why on my last reply I used the word 'Please'. I didn't want to impose anything on anyone. I understand that everyone is free to do as they wish.

Anyway many thanks
 
Last edited:

max123

Well-Known Member
Licensed User
Longtime User
And @Star-Dust , I'm Italian too.... from Varese and I have an house to Sicily too

Quindi a saperlo avremo potuto discuterne in italiano, ma siccome gli altri utenti non sono italiani é andato bene l'inglese come di consueto.
 

hdtvirl

Active Member
Licensed User
Longtime User
Star-Dust Thank you for your quick response, I have just tried your fix out and it works without the error.


Thank you very much.

Regards

hdtvirl
 
Top