If you want to use it, you can directly use the following 2 libraries: https://github.com/hdodenhof/CircleImageView https://github.com/vinc3m1/RoundedImageView
In terms of principle...
Just use PorterDuffXfermode
on Paint
First use the canvas.drawCircle method to draw a circle, then set PorterDuffXfermode to use orthogonal mode,
Draw the bitmap again, so that the two graphics drawn before and after only show the intersection part...the picture will only be a circle..
The second way is Shader
To understand it simply, it can be thought of as making a bitmap into a paint texture, and then using paint to draw a circle directly on the canvas
If you want to use it, you can directly use the following 2 libraries:
https://github.com/hdodenhof/CircleImageView
https://github.com/vinc3m1/RoundedImageView
In terms of principle...
on PaintJust use PorterDuffXfermode
First use the canvas.drawCircle method to draw a circle, then set PorterDuffXfermode to use orthogonal mode,
Draw the bitmap again, so that the two graphics drawn before and after only show the intersection part...the picture will only be a circle..
The second way is Shader
To understand it simply, it can be thought of as making a bitmap into a paint texture, and then using paint to draw a circle directly on the canvas
The above two libraries have source code...