Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
val source = ImageDecoder.createSource(assets, "image.jpg")
val listener = ImageDecoder.OnHeaderDecodedListener { decoder, info, src ->
decoder.setPostProcessor { canvas ->
// This will create rounded corners.
val path = Path()
path.fillType = Path.FillType.INVERSE_EVEN_ODD
val width = canvas.width
val height = canvas.height
path.addRoundRect(0f, 0f, width.toFloat(), height.toFloat(), width / 2.toFloat(), height / 2.toFloat(), Path.Direction.CW)
val paint = Paint()
paint.isAntiAlias = true
paint.color = Color.TRANSPARENT
paint.xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC)
canvas.drawPath(path, paint)
val drawable = ImageDecoder.decodeDrawable(source, listener)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment