Load image from web

NetStorm

Member
Licensed User
Longtime User
Is there a way I can load an image directly in to a imageView via a http link?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The FlickrViewer is a very good example.
Here is a simple code that downloads a single image:
B4X:
Sub Process_Globals
    Dim hc As HttpClient
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        hc.Initialize("hc")
    End If
    Dim req As HttpRequest
    req.InitializeGet("http://www.b4x.com/android/images/logo.png")
    hc.Execute(req, 1)
End Sub

Sub hc_ResponseSuccess (Response As HttpResponse, TaskId As Int)
    Dim b As Bitmap
    b.Initialize2(Response.GetInputStream)
    Activity.SetBackgroundImage(b)
    Response.Release
End Sub

Sub hc_ResponseError (Response As HttpResponse, Reason As String, StatusCode As Int, TaskId As Int)
    Log("Error connecting: " & Reason & " " & StatusCode)
    If Response <> Null Then
        Log(Response.GetString("UTF8"))
        Response.Release
    End If
End Sub
Don't forget to add a reference to the Http library. The Http library version should be 1.10 or above.
 
Upvote 0

ZJP

Active Member
Licensed User
Longtime User
Hi,

FlickrViewer is the perfect example to find one (or more) picture in the html jungle (In French "Chercher une aiguille dans une botte de foin" / "Finding a needle in a haystack").
This current example is complementary. Ideal if the url of the picture is known

Tx.

JP
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…