B4A Library AS Gallery - show images from folders (image- and video-thumbnails)

I want to share my class to create a image preview list like in the gallery app.
This class is based on xCustomListView and PreoptimizedCLV.
The class is creating a cached thumbnail of a image if needed, to avoid performance issues on scrolling.
The cache folder is created here: File.MakeDir(File.DirInternal , "cache")

You can set the tile count, per default it is 4.
I have tested the class with .mp4,.jpg and .png files.

Example of usage:
    Dim rp As RuntimePermissions
    rp.CheckAndRequest(rp.PERMISSION_READ_EXTERNAL_STORAGE)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)

    Dim tmp_lst As List : tmp_lst.Initialize2(Array As String(File.DirRootExternal & "/Snapchat",File.DirRootExternal & "/Fast InstaSaver"))

    ASGallery1.WildCards = "*.jpg,*.png,*.jpeg,*.bmp"',*.mp4"
    ASGallery1.GetContent(tmp_lst)
Screenshot_20200531-174016.jpg



ASGallery
Author: Alexander Stolte
Version: 1.03

  • ASGallery
    • Events:
      • PreviewClick (path As String, isImage As Boolean)
    • Functions:
      • Class_Globals As String
      • CreateFileAndTime (Name As String, Time As Long, dir As String) As FileAndTime
      • CreateMyImageData (IndexOfFirstImage As Int, lst_image_filename As List) As MyImageData
      • DesignerCreateView (Base As Object, Lbl As Label, Props As Map) As String
        Base type must be Object
      • GetContent (lst_dirs As List)
      • Initialize (Callback As Object, EventName As String) As String
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • setWildCards (wildcards As String) As String
      • xclv_main_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int) As String
    • Properties:
      • WildCards
  • FileAndTime
    • Fields:
      • dir As String
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • Name As String
      • Time As Long
    • Functions:
      • Initialize
        Initializes the fields to their default value.
  • MyImageData
    • Fields:
      • IndexOfFirstImage As Int
      • IsInitialized As Boolean
        Tests whether the object has been initialized.
      • lst_image_filename As List
    • Functions:
      • Initialize
        Initializes the fields to their default value.
Changelog
  • 1.00
    • Release
  • 1.01
    • add get xCustomListView
    • add get mbase
    • add bug fixes
  • 1.02
    • add BitmapAsync - only for image files
  • 1.03
    • automatically rotates the preview image when it is horizontal
    • new dependency JpegUtils
Have Fun :)
 

Attachments

  • B4A Example.zip
    5.2 KB · Views: 937
  • ASGallery.bas
    14.4 KB · Views: 883
Last edited:

cambopad

Active Member
Licensed User
Longtime User
Cool lib! Will it face Out of memory issue when loading hundreds of photos?
 

Alexander Stolte

Expert
Licensed User
Longtime User
I've never had any problems and I've displayed my entire gallery with it and that's over 4 thousand pictures. The lib. Makes a thumbnail of the pictures and caches that, so the pictures that are called are very small in size
 

Alexander Stolte

Expert
Licensed User
Longtime User
Update
The performance for unchached images is much better now
  • 1.01
    • add get xCustomListView
    • add get mbase
    • add bug fixes
  • 1.02
    • add BitmapAsync - only for image files
 

Alexander Stolte

Expert
Licensed User
Longtime User
how to change asgallery background color?
Try
B4X:
    ASGallery1.Base.Color = xui.Color_Red
    'or
    ASGallery1.xCustomListView.AsView.Color = xui.Color_Red
But please don't expect further support, this is more an example project to work on yourself.
 
Top