1000 Imageviews created by code loading pictures from a url

DonManfred

Expert
Licensed User
B4X:
Sub Button1_Click
    For i = 0 To 100
        Dim zufall As Int = Rnd(0, flist.Size)
        'Log(flist.Get(zufall))
        Dim img As ImageView
        img.Initialize("iv")
        Dim posx As Int = Rnd(0,100%x-100dip)
        Dim posy As Int = Rnd(0,100%y-100dip)
        Activity.AddView(img,posx,posy,100dip,100dip)
        il.loadImg("http://snapshots.basic4android.de/"&flist.Get(zufall),img)      
    Next
End Sub
il is of type uil. uil is an Acronym for UniversalImageLoader. uil is not released actually.


 
Last edited:

Erel

Administrator
Staff member
Licensed User
In order to avoid OOM you need to load each image and draw it with Canvas instead of adding an ImageView.
 

DonManfred

Expert
Licensed User
In order to avoid OOM you need to load each image and draw it with Canvas instead of adding an ImageView.
Tell this the author if the lib ;-)
I just wrote a wrapper which calls some of the methods of this lib.
B4X:
il.loadImg("http://snapshots.basic4android.de/"&flist.Get(zufall),img)
the uilobject (the wrapper) just call loadImg with the url and the reference to the imageview. Rest is done by the native jar
'Acceptable URIs examples
'"http://site.com/image.png" // from Web
'"file:///mnt/sdcard/image.png" // from SD card
'"file:///mnt/sdcard/video.mp4" // from SD card (video thumbnail)
'"content://media/external/images/media/13" // from content provider
'"content://media/external/video/media/13" // from content provider (video thumbnail)
'"assets://image.png" // from assets
But i did not test the content uris... First i need to figure out what the hell that is :) Honestly i did do do anything with that before :)
 

KMatle

Expert
Licensed User
In order to avoid OOM you need to load each image and draw it with Canvas instead of adding an ImageView.
I have a scrollview. On it, I add panels at runtime and initialize canvases to it. On those canvases I use ONE Bitmap for all images and draw with it on them.

As far as I understood, this is the optimal way?
 

sorex

Expert
Licensed User
no, I think that Erel meant that it's better in that example to just copy it to the canvas.

indeed, as long as they don't need to be clickable or movable you could just copy it to 1 canvas as the memory size of that won't change
if you copy 1 or 5738 images to it.
 
Top