u need to download the page source and then parsing the img tag for the url name. (maybe regular expressions will help.)
not always possible if java script is used.
can also difficult if the url embedding other external pages.
Dim Job As HttpJob
'...
'Dim Image1 As Image
Dim Out As OutputStream = File.OpenOutput(File.DirApp, "1.png")
Job.GetBitmap.WriteToStream(Out) 'from web request
'Image1.WriteToStream(Out) 'from image direct
Out.Close
Sub DownloadImage(Link As String, filename As String)
Dim job As HttpJob
job.Initialize("", Me) 'note that the name parameter is no longer needed.
job.Download(Link)
Wait For (job) JobDone(job As HttpJob)
If job.Success Then
Dim out As OutputStream = File.OpenOutput(File.DirApp, "test.jpg", False)
job.GetBitmap.WriteToStream(out) 'from web request
out.Close
End If
job.Release
End Sub
B4X:
B4J Version: 6.30
Parsing code. (0.04s)
Compiling code. (0.13s)
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
Compiling generated Java code. Error
B4J line: 134
job.GetBitmap.WriteToStream(out) 'from web re
javac 1.8.0_181
src\b4j\example\main.java:423: error: cannot find symbol
_job._getbitmap().WriteToStream((java.io.OutputStream)(_out.getObject()));
^
symbol: method _getbitmap()
location: variable _job of type httpjob
1 error
Also the text is to super some text over the image.
I think the problem is that this is an non-ui application.
If I use jOkHttpUtils2_NONUI then job.GetBitmap.WriteToStream(out) comes with an error
unknown member: getbitmap
This is a NonUI web server program
Sub DownloadImage(Link As String, filename As String)
Dim job As HttpJob
job.Initialize("", Me) 'note that the name parameter is no longer needed.
job.Download(Link)
Wait For (job) JobDone(job As HttpJob)
If job.Success Then
Dim out As OutputStream = File.OpenOutput(File.DirApp, "test.jpg", False)
File.Copy2(job.GetInputStream, out)
out.Close
End If
job.Release
End Sub
Note: This is only going to properly work if all your downloading is an image (in this case a JPG image), not an HTML file containing an image and/or image links.