If File.Exists(File.DirDefaultExternal, image&n".jpg") Then
foto.Bitmap = LoadBitmap(File.DirDefaultExternal, image&n".jpg")
Else
'I've to get and save the image, then load it
foto.Bitmap = LoadBitmap(File.DirDefaultExternal, image&n".jpg")
End If
Files are about one MBI recommend you to use HttpUtils. Especially if the image files are large.
This is how I finally do:You should use HttpUtils.GetInputStream with File.Copy2. There is an example here: http://www.b4x.com/forum/54676-post6.html
If HttpUtils.IsSuccess(imgurl) Then
Dim b As Bitmap
b = HttpUtils.GetBitmap(imgurl)
Dim out As OutputStream
out = File.OpenOutput(File.DirInternal, nimagen&".jpg", True)
File.Copy2(HttpUtils.GetInputStream(imgurl), out)
out.Close
foto.Bitmap = LoadBitmap(File.DirInternal, nimagen&".jpg")
End If
Maybe, something like this?:You are not doing anything with 'b' ?
Note that it is better to use LoadBitmapSample when working with large images.
If HttpUtils.IsSuccess(imgurl) Then
Dim out As OutputStream
out = File.OpenOutput(File.DirInternal, nimagen&".jpg", True)
File.Copy2(HttpUtils.GetBitmap(imgurl), out)
out.Close
foto.Bitmap = LoadBitmap(File.DirInternal, nimagen&".jpg")
End If
What I only want to do is download and save the image file... How can I do this?If you are only interested in the bitmap then you should not copy the file. Just call HttpUtils.GetBitmap.
If HttpUtils.IsSuccess(imgurl) Then
Dim out As OutputStream
out = File.OpenOutput(File.DirInternal, nimagen&".jpg", True)
File.Copy2(HttpUtils.GetInputStream(imgurl), out)
out.Close
foto.Bitmap = LoadBitmap(File.DirInternal, nimagen&".jpg")
End If
Thank you!!!Here:
B4X:If HttpUtils.IsSuccess(imgurl) Then Dim out As OutputStream out = File.OpenOutput(File.DirInternal, nimagen&".jpg", True) File.Copy2(HttpUtils.GetInputStream(imgurl), out) out.Close foto.Bitmap = LoadBitmap(File.DirInternal, nimagen&".jpg") End If
If you are only interested in the bitmap then you should not copy the file. Just call HttpUtils.GetBitmap.
Dim APhotoLink as string
APhotoLink = "http://www.petango.com/sms/photos/592/2bfc7af4-87b5-4725-8bc2-0aef83b5042b.jpg"
lvPets.AddTwoLinesAndBitmap(jName, otherInfo, [B]HttpUtils.GetBitmap(APhotoLink)[/B])
Dim APhotoLink as string
Dim b As Bitmap
APhotoLink = "http://www.petango.com/sms/photos/592/2bfc7af4-87b5-4725-8bc2-0aef83b5042b.jpg"
b = HttpUtils.GetBitmap(APhotoLink)
lvPets.AddTwoLinesAndBitmap(jName, otherInfo, loadbitmap(b))
Sub Process_Globals
Dim ImageUrl As String
ImageUrl = "http://www.petango.com/sms/photos/592/d485b787-aaa6-4d66-9fb6-4c6e17c8022e_TN1.jpg"
End Sub
Sub Globals
Dim ListView1 As ListView
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
HttpUtils.CallbackActivity = "Main"
HttpUtils.CallbackJobDoneSub = "JobDone"
HttpUtils.CallbackUrlDoneSub = "UrlDone"
HttpUtils.Download("GET Job1", ImageUrl) 'start
End Sub
Sub Activity_Resume
If HttpUtils.Complete = True Then JobDone(HttpUtils.Job)
End Sub
Sub UrlDone(Url As String)
Log(Url & " done")
End Sub
Sub JobDone (Job As String)
Select Job
Case "GET Job1"
If HttpUtils.IsSuccess(ImageUrl) Then
Dim b As Bitmap
b = HttpUtils.GetBitmap(ImageUrl)
ListView1.AddTwoLinesAndBitmap2("test", "test", b, "link")
End If
End Select
HttpUtils.Complete = False
End Sub
Sub Globals
Type ListViewData (FirstRow As String, SecondRow As String, ANum As String, Photo As Bitmap)
'...
Dim abmpurl As String
Dim abmp As Bitmap
End Sub
Sub Activity_Create(FirstTime As Boolean)
HttpUtils.CallbackActivity = "actPets" 'Current activity name.
HttpUtils.CallbackJobDoneSub = "JobDone"'"GetPageFromPetango"
HttpUtils.CallbackUrlDoneSub = "URLDone"
'...
HttpUtils.Download("GetPageFromPetango", Main.AnimalURL)
End Sub
Sub JobDone (Job As String)
Select Job
Case "GetPageFromPetango"
ParsePetangoPage
Case "GetAnimalPhoto"
If HttpUtils.IsSuccess(abmpurl) Then
abmp = HttpUtils.GetBitmap(abmpurl)
End If
End Select
HttpUtils.Complete = False
End Sub
Sub ParsePetangoPage
'declare some variables
'...
Dim txtrdr As TextReader
txtrdr.Initialize(HttpUtils.GetInputStream(Main.AnimalURL))
Dim line As String
line = txtrdr.ReadLine
Do While line <> Null
Dim lvd As ListViewData
lvd.Initialize
Dim b As Bitmap
'Animal Photo
If line.Contains("img class=") Then
line = line.SubString(line.IndexOf("w"))
line = "<a href=" & QUOTE & "http://www.petango.com/webservices/adoptablesearch/" & line
line = line.SubString2(line.IndexOf("src="), line.IndexOf("alt="))
line = line.SubString(line.IndexOf(QUOTE & "h"))
line = line.SubString2(line.IndexOf("http"),line.Length-1)
line = line.Replace(QUOTE, "")
abmpurl = line
HttpUtils.Download("GetAnimalPhoto", abmpurl)
End If
'Animal Name
If line.Contains("list-animal-name") Then
line = line.SubString(line.IndexOf("w"))
line = "<a href=" & QUOTE & "http://www.petango.com/webservices/adoptablesearch/" & line
AName = line
jName = AName.SubString2(AName.IndexOf(">")+1, AName.IndexOf("</"))
End If
'Animal ID
If line.Contains("list-animal-id") Then
ANumber = line
ANumber = ANumber.SubString2(ANumber.IndexOf(">")+1, ANumber.IndexOf("</"))
End If
'Animal Sex
If line.Contains("list-animal-sexSN") Then
ASex = line
ASex = ASex.SubString2(ASex.IndexOf(">")+1, ASex.IndexOf("</"))
End If
'Animal Age
If line.Contains("list-animal-age") Then
AAge = line
AAge = AAge.SubString2(AAge.IndexOf(">")+1, AAge.IndexOf("</"))
End If
'Animal Breed
If line.Contains("list-animal-breed") Then
ABreed = line
ABreed = ABreed.SubString2(ABreed.IndexOf(">")+1, ABreed.IndexOf("</"))
End If
'End of this animal's table row
If line = "</td>" Then
lvd.FirstRow = jName
lvd.SecondRow = AAge & " " & ASex
lvd.ANum = ANumber
lvd.Photo = abmp
lvPets.AddTwoLinesAndBitmap2(lvd.FirstRow, lvd.SecondRow, lvd.Photo, lvd)
Else
'Don't do anything
End If
line = txtrdr.ReadLine
Loop
txtrdr.Close
End Sub
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?