简体   繁体   中英

MediaStore.Images.Media.getBitmap takes too much time

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?

我没有使用全尺寸图像,而是使用它们的缩略图,并且比以前更快。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM