圆角图片处理

//图片圆角处理
public Bitmap getRoundedBitmap(Bitmap mBitmap) {
    //创建新的位图
    Bitmap bgBitmap = Bitmap.createBitmap(mBitmap.getWidth(), mBitmap.getHeight(), Bitmap.Config.ARGB_8888);
    //把创建的位图作为画板
    Canvas mCanvas = new Canvas(bgBitmap);

    Paint mPaint = new Paint();
    Rect mRect = new Rect(0, 0, mBitmap.getWidth(), mBitmap.getHeight());
    RectF mRectF = new RectF(mRect);
    //设置圆角半径为20
    float roundPx = 10;
    mPaint.setAntiAlias(true);
    //先绘制圆角矩形
    mCanvas.drawRoundRect(mRectF, roundPx, roundPx, mPaint);

    //设置图像的叠加模式
    mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    //绘制图像
    mCanvas.drawBitmap(mBitmap, mRect, mRect, mPaint);

    return bgBitmap;
}
gdky005 wechat
加微信好友,一起交流