0

I'd like to check if there is at least one human face in my photos in external storage.

I query external contents like this:

   queryTimeTaken += measureTimeMillis {
        try {
            cursor = context.contentResolver.query(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                projection,
                null,
                null,
                sortOrderAndFetchLimit
            )
        } catch (e: Exception) {
            println("Error when executing query(): $e")
        }
    }

get uri takes 0.004s

getUriTimeTaken += measureTimeMillis {
    uri = ContentUris.withAppendedId(
        MediaStore.Images.Media.EXTERNAL_CONTENT_URI, cursor.getInt(cursor.getColumnIndex(MediaStore.Images.ImageColumns._ID)).toLong())

}

getBitmap() takes too much time. It takes about 10s.

getBitmapTimeTaken += measureTimeMillis {
    bitmap = MediaStore.Images.Media.getBitmap(context.contentResolver, uri)
}

getBitmap() takes 90% of total time, so it is a bottle neck here. Is there anything I can do to make it faster?

John
  • 1,139
  • 3
  • 16
  • 33

1 Answers1

0

Instead of full sized images, I use thumbnails of them and it is way faster than before.

John
  • 1,139
  • 3
  • 16
  • 33