Skip to content

Instantly share code, notes, and snippets.

@cloudbank
Created May 27, 2020 05:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cloudbank/b853889ed6ebe8883446535ec455dde8 to your computer and use it in GitHub Desktop.
Save cloudbank/b853889ed6ebe8883446535ec455dde8 to your computer and use it in GitHub Desktop.
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