Android Question download the image and resize them

cup319

Member
download images
B4X:
Sub DownloadImage(Link As String, iv As ImageView)
    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
        iv.Bitmap = job.GetBitmap 'replace with iv.Bitmap = job.GetBitmap in B4A / B4i
    End If
    job.Release
End Sub

DownloadImage(tvurl.Get(i), ImageViews(i))

i have not save the pictures to anywhere,and i need to set the pictuers in (10%x, 15%y)
the loadbitmapresize maybe works ,actually something wrong happend , help needed,THAMKS

///////////////////////////////////////////
LoadBitmapResize(ImageViews(i), ImageViews(i), 10%x, 15%y, True)'设置图片大小
 

JohnC

Expert
Licensed User
Longtime User
You are not calling the "LoadBitmapResize" routine properly.

You would need to first save the image in the imageview to a file, then you can use the LoadBitmapResize to load the image in from the file and return a different size bitmap.

See this tutorial for more info:

 
Upvote 0

cup319

Member
You are not calling the "LoadBitmapResize" routine properly.

You would need to first save the image in the imageview to a file, then you can use the LoadBitmapResize to load the image in from the file and return a different size bitmap.

See this tutorial for more info:




B4X:
Sub DownloadAndSave (Url As String, Dir As String, FileName As String) As ResumableSub
   Dim j As HttpJob
   j.Initialize("", Me)
   j.Download(Url)
   Wait For (j) JobDone(j As HttpJob)
   If j.Success Then
       Dim out As OutputStream = File.OpenOutput(Dir, FileName, False)
       File.Copy2(j.GetInputStream, out)
       out.Close
   End If
   j.Release
   Return j.Success
End Sub


Wait For (DownloadAndSave(URL, File.DirInternal, "map_large.jpg")) Complete (Success As Boolean)
If Success Then
 ...
 
 Dim bg As Bitmap = LoadBitmapResize(File.DirAssets, "bg.png", ImageView1.Width, ImageView1.Height, True)
ImageView1.SetBackgroundImage(bg).Gravity = Gravity.CENTER



any examples for these,below?
File.DirInternal
File.DirAssets
 
Upvote 0
Top