//設置圓角圖片或者圓形圖片
privateBitmapSettingBitmap(Bitmap bitmap) {
introundx =0;
intrect_left,rect_right,rect_top,rect_bottom;
intleft,right,top,bottom;
intwidth = bitmap.getWidth();
intheight = bitmap.getHeight();
if(width <= height) {
roundx = width /2;
left =0;
top =0;
right = width;
bottom = width;
intclip = (height - width) /2;
rect_left =0;
rect_right = width;
rect_top = clip;
rect_bottom = height - clip;
}else{
roundx = height /2;
left =0;
top =0;
right = height;
bottom = height;
intclip = (width - height) /2;
rect_left = clip;
rect_right = width - clip;
rect_top =0;
rect_bottom = height;
}
Bitmap bitmap1 = Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_8888);
Canvas canvas =newCanvas(bitmap1);
Paint paint =newPaint();
paint.setColor(Color.RED);
paint.setAntiAlias(true);//去鋸齒
canvas.drawARGB(0,0,0,0);
Rect rect =newRect(rect_left,rect_top,rect_right,rect_bottom);
Rect rect_dst =newRect(left,top,right,bottom);
RectF rectF =newRectF(rect_dst);
//? ? ? ? canvas.drawCircle(roundx,roundx,roundx,paint);
/**
* rect:RectF對象命满。
rx:x方向上的圓角半徑褒繁。
ry:y方向上的圓角半徑壶熏。
paint:繪制時所使用的畫筆瘫里。
*/
canvas.drawRoundRect(rectF,30,30,paint);
paint.setXfermode(newPorterDuffXfermode(PorterDuff.Mode.SRC_IN));// 設置兩張圖片相交時的模式
/**
* Rect src: 是對圖片進行裁截铸鹰,若是空null則顯示整個圖片
RectF dst:是圖片在Canvas畫布中顯示的區(qū)域孔轴,
大于src則把src的裁截區(qū)放大蓬衡,
小于src則把src的裁截區(qū)縮小。
*/
canvas.drawBitmap(bitmap,rect,rect_dst,paint);
if(bitmap != bitmap1) {
// Same bitmap is returned if sizes are the same
bitmap.recycle();
}
returnbitmap1;
}