Wish Image(url)

Daestrum

Expert
Licensed User
Longtime User
Would it be possible to have image from url added ?
equivalent to java
B4X:
public static Image ImageFromURL(String url){
          return new Image(url);
}
I have coded it in the #if java block, but it's a pain to have to use runmethod(...) etc to access it.
So it could become
B4X:
Dim img As Image
img  = ImageFromURL(theURL)

As I am currently trying
B4X:
img.Initialize("https://...","")
but this changes the slashes and you get a file not found error when the address is in a string variable.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
While the code you posted looks nice and simple it downloads the image on the main thread which will cause the whole app to freeze until it completes.

You can use this sub to call this code without inline java:
B4X:
Sub ImageFromUrl(url As String) As Image
   Dim jo As JavaObject
   jo.InitializeNewInstance("javafx.scene.image.Image", Array(url))
   Return jo
End Sub
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…