Created
November 12, 2021 13:36
-
-
Save oliverspryn/a501ec1853bcaccf0b2983a56336226a to your computer and use it in GitHub Desktop.
The image decoder with proper support for testing API-dependent code
This file contains hidden or 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 @Inject constructor( | |
| @Named(BuildModule.sdkVersion) private val sdkVersion | |
| ) { | |
| fun decodeAndProcessImage(uri: Uri) { | |
| val bitmap = if (sdkVersion < 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