Hi,
I found that the default ImageView class was not flexible enough, so I wrote my own ImageView class, based on webView.
To use it, just pass an AnchorPane to the first param of initialize:
Basically it just loads images in a webview, but gives more flexibility on those points:
Note:
Don't forget to call the method "LoadImageDelayed" every time you modify something to reload the Html.
Note:
To fully test this library, try resizing the window and see how the different fit values affect the image.
Note:
the methods "ImagePosition" and "ImageOrientation" don't work at the moment. If someone can help figuring out why, that would be awesome.
Enjoy.
I found that the default ImageView class was not flexible enough, so I wrote my own ImageView class, based on webView.
To use it, just pass an AnchorPane to the first param of initialize:
B4X:
Sub Process_Globals
Private apWiv As AnchorPane
Private iv1 As WebImageView
End Sub
Sub AppStart (Form1 As Form, Args() As String)
apWiv.Initialize("")
iv1.Initialize(apWiv, Me, "iv")
iv1.SetImage(File.Combine(File.DirAssets, "01.jpg"))
iv1.BackColor = "Black" 'css color
iv1.ImageFit = "CONTAIN"
iv1.Tag = "WebImageView 1"
End Sub
Sub iv_MouseClicked(EventData As MouseEvent)
Dim iv As WebImageView = Sender
Log($"Clicked Tag: ${iv.Tag}"$)
End Sub
Basically it just loads images in a webview, but gives more flexibility on those points:
- Async loading of images, because WebView loads it's content on a separate thread. (I have a list of images to load, and loading one by one with imageView was too long)
- Images can be anchored
- Images can be rescaled
- Load images from URLs
- Set the Fitting of images in the view: Contain, Fill, Cover, None
- Set the background color in case of letterboxing
- Can write additional css.
Note:
Don't forget to call the method "LoadImageDelayed" every time you modify something to reload the Html.
Note:
To fully test this library, try resizing the window and see how the different fit values affect the image.
Note:
the methods "ImagePosition" and "ImageOrientation" don't work at the moment. If someone can help figuring out why, that would be awesome.
Enjoy.
Attachments
Last edited: