[英]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 获得uri需要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. getBitmap()需要太多时间。 It takes about 10s.
大约需要10秒钟。
getBitmapTimeTaken += measureTimeMillis {
bitmap = MediaStore.Images.Media.getBitmap(context.contentResolver, uri)
}
getBitmap() takes 90% of total time, so it is a bottle neck here. getBitmap()占用总时间的90%,因此这里是瓶颈。 Is there anything I can do to make it faster?
我有什么可以做得更快?
我没有使用全尺寸图像,而是使用它们的缩略图,并且比以前更快。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.