Android Question Image downloader service and no extensions

bluedude

Well-Known Member
Licensed User
Longtime User
Hi,

I have some issues with the image downloader service when the URL has no file extension, any suggestions?
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
Sub Activity_Resume
    Dim links As Map
    links.Initialize
    links.Put(ImageView1, "http://snapshots.basic4android.de/filewithoutext")
    links.Put(ImageView2, "http://www.b4x.com/basic4android/images/SS-2013-03-04_11.42.38.png")
    links.Put(ImageView3, "http://www.b4x.com/basic4android/images/SS-2013-03-04_11.52.19.png")
    links.Put(ImageView4, "http://www.b4x.com/basic4android/images/SS-2012-02-06_12.45.56.png")
    CallSubDelayed2(ImageDownloader, "Download", links)
End Sub
The file http://snapshots.basic4android.de/filewithoutext IS an image... (it´s the upper one)
imagedownloader.png
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Mmm, interesting. I do the same. The issue is that it does not seem to fetch the image.

Need to investigate it further.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
try this URL

B4X:
Sub Activity_Resume
    Dim links As Map
    links.Initialize
    links.Put(ImageView1, "http://i1.adis.ws/i/wehkamp/248004_pb_01")
    links.Put(ImageView2, "http://www.b4x.com/basic4android/images/SS-2013-03-04_11.42.38.png")
    links.Put(ImageView3, "http://www.b4x.com/basic4android/images/SS-2013-03-04_11.52.19.png")
    links.Put(ImageView4, "http://www.b4x.com/basic4android/images/SS-2012-02-06_12.45.56.png")
    CallSubDelayed2(ImageDownloader, "Download", links)
End Sub
imagedownloader2.png
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Hi Erel,
You mean I should replace this iv.SetBackgroundImage(bmp) with LoadBitMapSample? The Job only has a method to do getbitmap.

Or should I do a change in the GetBitMap itself?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can add this sub to HttpJob (you will need to use HttpUtils2 source code instead of the library):
B4X:
'Returns the response as a bitmap loaded with LoadBitmapSample.
Public Sub GetBitmapSample(Width As Int, Height As Int) As Bitmap
   Return LoadBitmapSample(HttpUtils2Service.TempFolder, taskId, Width, Height)
End Sub
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Hi,

I use the source code but the problem is that I want to keep aspect ratio because this is a real issue overall. How can I pre calculate the aspect ratio so I can set that with Width and Height before I download?
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Hi,

That seems to solve the large image problem, great. Now i'm wondering I i lose aspect ratio if I resize them slighty without taking aspect ratio into account.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Keeping the aspect ratio is quite complicated here. It will require finding the bitmap size without loading it (there are libraries that can do it) and then calculating the correct size. You can then load it with LoadBitmapSample. The last step will be to resize the image to the correct size as the bitmap loaded with LoadBitmapSample will usually be larger than the specified size.
 
Upvote 0
Top