Home > Back-end >  Loading images from folder take to much time
Loading images from folder take to much time

Time:10-16

I have a lot of pictures on a path , and i move picture to this path , loading pictures and displaying them on recyclerView take a lot of time , and i am using a fragment , when i change fragment and back to the one that display pictures , it take again a lot of time to load pictures .

any suggestion to load pictures fast ?

  suspend fun getImages() = try {
        val path = Environment.getExternalStorageDirectory()
            .toString()   "Here folder path "
        val directory = File(path)

       

        val files = directory.listFiles()
        if (files.isEmpty()) {
          //
        } else {


        }
        for (i in files.indices) {
            println( files[i].name)


            val myBitmap = BitmapFactory.decodeFile(files[i].getAbsolutePath())
            var path = files[i].getAbsolutePath()
            var fileName = files[i].name
            var picture = Picture(myBitmap, path, fileName)
            if (picture != null) {
                listPictures.add(picture)
            }
        }
        withContext(Dispatchers.Main){
            myAdapter.notifyDataSetChanged()

        }

    } catch (e: Exception) {
      

    }
```

CodePudding user response:

I would suggest using glide, or something like it, to load images. https://github.com/bumptech/glide

CodePudding user response:

You're going to want to do a library, so go ahead and check these out, I added for Android and for JavaScript.

-> https://www.geeksforgeeks.org/top-5-image-loading-libraries-in-android/

-> https://www.qandeelacademy.com/articles/23-awesome-javascript-loaders-libraries

  • Related