Created
May 27, 2020 05:33
-
-
Save cloudbank/b853889ed6ebe8883446535ec455dde8 to your computer and use it in GitHub Desktop.
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
private fun updateImageWithImageDecoder(assetFileName: String, imageView: ImageView) { | |
val context = requireContext() | |
viewLifecycleOwner.lifecycleScope.launch { | |
val d = withContext(Dispatchers.Default) { | |
val source = ImageDecoder.createSource(context.assets, assetFileName) | |
val drawable = ImageDecoder.decodeDrawable(source) | |
return@withContext drawable | |
} | |
withContext(Dispatchers.Main) { | |
imageView.setImageDrawable(d) | |
if (d is AnimatedImageDrawable) { | |
d.start() | |
d.repeatCount = AnimatedImageDrawable.REPEAT_INFINITE | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment