Skip to content

Instantly share code, notes, and snippets.

@oliverspryn
Last active November 12, 2021 13:35
Show Gist options
  • Save oliverspryn/519e3cf2c581a7d8682fd0a1f934e7f3 to your computer and use it in GitHub Desktop.
Save oliverspryn/519e3cf2c581a7d8682fd0a1f934e7f3 to your computer and use it in GitHub Desktop.
A function which spans multiple API versions to decode a bitmap
class ImageController {
fun decodeAndProcessImage(uri: Uri) {
val bitmap = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
MediaStore.Images.Media.getBitmap(contentResolver, uri)
} else {
val source = ImageDecoder.createSource(contentResolver, uri)
ImageDecoder.decodeBitmap(source)
}
// Do something with the Bitmap
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment