Using Paint.setxfermode
Reference link: From the blog, please click here
To get things Circleimageview, split into two parts: Create a circle bitmap use canvas to create a circular bitmap
Private Bitmap Createroundconerimage (Bitmap source)
{
final Paint Paint = new Paint ();
Paint.setantialias (true);
Create a Bitmap object of the same size
Bitmap target = Bitmap.createbitmap (Mwidth, Mheight, config.argb_8888);
Encapsulated as Canvas object
Canvas Canvas = new Canvas (target);
RECTF rect = new RECTF (0, 0, source.getwidth (), Source.getheight ());
Draw the circle through the canvas into a circular canvas
canvas.drawroundrect (rect, Mradius, Mradius, paint);
Sets how the brush is stacked
paint.setxfermode (new Porterduffxfermode (PorterDuff.Mode.SRC_IN));
Draw the original picture on the canvas
canvas.drawbitmap (source, 0, 0, paint);
Remove Bitmap object return
target;
}
Draw the generated circular bitmap object
Add in OnDraw (Canvas Canvas):
Canvas.drawbitmap (Createroundconerimage (MSRC), 0, 0, NULL);
Using shader
Reference Links: http://blog.csdn.net/lmj623565791/article/details/41967509 drawable to bitmap bitmap to Bitmapshader via paint Drawcircle the Drawable object to bitmap by Paint objects on the canvas object
Public Bitmap Drawable2bitmap (drawable drawable) {
if (drawable = null) {
retrurn null;
}
if (drawable instanceof bitampdrawable) {
retrun (bitampdrawble) drawable). Getbitmap ();
int w = drawble.getintrisicwidth ();
int h = drawble.getintrisicheight ();
Bitmap Newbitmap = Bitmap.createbitmap (w,h,bitmap.config.argb_8888);
Canvas Canvas = new Canvas (newbitmap);
Drawable.setbounds (0,0,w,h);
Drawable.draw (Canvas);
return newbitamp;
}
Associating Bitmapshader with the bitmap to be displayed
Mmatrix.setscale (Scale,scale),//set magnification multiples
mbitmapshader.setlocalmatrix (mmatrix);
Bitmapshader Mbitmapshader = new Bitmapshader (newbitmap,tilemode.clamp,tilemode.clamp);
Mbitmappaint.setshader (Mbitmapshader);
To draw a circle again
Slightly