Deprecated “getBitmap” with API 29. Any alternative codes?

前端 未结 9 2242
渐次进展
渐次进展 2020-12-15 20:25

My onActivityResult is not working because getBitmap is deprecated, any alternative codes to achieve this?

here are the codes that needs to

9条回答
  •  太阳男子
    2020-12-15 20:50

    You can use:

        private fun getCapturedImage(selectedPhotoUri: Uri): Bitmap {
            val bitmap = when {
                Build.VERSION.SDK_INT < 28 -> MediaStore.Images.Media.getBitmap(
                    this.contentResolver,
                    selectedPhotoUri
                )
                else -> {
                    val source = ImageDecoder.createSource(this.contentResolver, selectedPhotoUri)
                    ImageDecoder.decodeBitmap(source)
                }
            }
    

提交回复
热议问题