Sviatoslav Melnychenko
1 min readAug 20, 2020

--

I have this problem. I have progress ring, background is simple grey circle, progress is an ark. A want to use a bitmap as progress. So, for bitmapPaint I use xfermode = PorterDuffXfermode(PorterDuff.Mode.SRC_IN)

Thing is, that it uses background circle as destination. To avoid it, I have to use canvas.saveLayer(null, null).

Basically it looks like this:

override fun onDraw(canvas: Canvas) {

canvas.drawArc(rect, startAngle, maxAngle, false, backgroundPaint)

canvas.saveLayer(null, null)

canvas.drawArc(rect, startAngle, angle, false, progressPaint)

progressBitmap?.let {

canvas.drawBitmap(it, null, fullRect, bitmapPaint)

}

canvas.restore()

}

Can I make it without canvas.saveLayer(null, null)? This is kind of expensive operation. So, my goal is that bitmap drawing uses only progress as destination.

--

--

Sviatoslav Melnychenko
Sviatoslav Melnychenko

No responses yet