Last active
November 12, 2021 13:35
-
-
Save oliverspryn/519e3cf2c581a7d8682fd0a1f934e7f3 to your computer and use it in GitHub Desktop.
A function which spans multiple API versions to decode a bitmap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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