I am using the code from Klaus's Scrollview example to show thumbnail images from jpegs in multiple directories
The first time the sub runs it is fine but when i change directories to show new thumbnails i get a crash. Memory error i think.
How can i release all the memory used each time a directory is changed
Thanks
The first time the sub runs it is fine but when i change directories to show new thumbnails i get a crash. Memory error i think.
How can i release all the memory used each time a directory is changed
Thanks
B4X:
Sub LoadImages
Dim files As List
Dim imagesFolder As String
If Bitmaps.IsInitialized=False Then
Bitmaps.Initialize
FileNames.Initialize
Else
Bitmaps.Clear
FileNames.Clear
End If
imagesFolder =RootDirectory & lvSource.GetItem(SourceDirNo)
files = File.ListFiles(imagesFolder) 'get all files in this folder
For i = 0 To files.Size - 1
DoEvents 'required for the ProgressDialog animation
Dim f As String
f = files.Get(i)
Log(i)
FileNames.Add(f)
Dim b As Bitmap
b.InitializeSample(imagesFolder, f, 200dip, 200dip) 'load the jpeg file and subsample it if it is too large.
Bitmaps.Add(b) 'add the bitmap to the bitmaps list.
Next
ScrollView1.Panel.Height = 200dip * Bitmaps.Size 'Set the inner panel height according to the number of images.
For i = 0 To Bitmaps.Size - 1
Dim iv As ImageView 'create an ImageView for each bitmap
iv.Initialize("ImageView")
Dim bd As BitmapDrawable
bd.Initialize(Bitmaps.Get(i))
iv.Background = bd 'set the background of the image view.
'add the image view to the scroll bar internal panel.
ScrollView1.Panel.AddView(iv, 5dip, 5dip + i * 200dip, ScrollView1.Width - 10dip, 190dip)
iv.Tag=i
Next
End Sub