androidimageviewandroid-imageviewdegrees

How to clip ImageView at the angle degree?


How to clip ImageView at the angle degree?

Like: this


Solution

  • Found a solution via path.arcTo and canvas.clipPath.

    private val oval = RectF()
    override fun onDraw(canvas: Canvas) {
    
        val x = width/2f
        val y = height/2f
        val radius = width/2f
    
        oval.left = x - radius
        oval.top = y - radius
        oval.right = x + radius
        oval.bottom = y + radius
    
        val path = Path()
        path.moveTo(x,y)
        path.arcTo(oval, startAngle, sweepAngle)
        path.close()
    
        canvas.clipPath(path);
        super.onDraw(canvas)
    }