Open ythy opened 1 year ago
以上方案会导致 引用的背景不透明 正确:
import androidx.appcompat.content.res.AppCompatResources
AppCompatResources.getDrawable(this,R.drawable.skin_theme_spring)
画圆
val decoder = ImageDecoder.decodeDrawable(source) { decoder, _, _ ->
val path = Path().apply {
fillType = Path.FillType.INVERSE_EVEN_ODD
}
val paint = Paint().apply {
isAntiAlias = true
color = Color.TRANSPARENT
xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC)
}
decoder.setPostProcessor { canvas ->
val length = min(canvas.width.toFloat(),canvas.height.toFloat())
val direction = Path.Direction.CW
path.addRoundRect(0f, 0f, length, length, length / 2, length / 2, direction)
canvas.drawPath(path, paint)
PixelFormat.TRANSLUCENT
}
}
AS-IS
TO-BE