CommonUtils.java 文件源码

java
阅读 47 收藏 0 点赞 0 评论 0

项目:TestChat 作者:
/**
 * 获取圆形图片
 *
 * @param bitmap 源bitmap
 * @return 圆形bitmap
 */
public static Bitmap getCircleBitmap(Bitmap bitmap) {
        Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(outBitmap);
        float roundSize;
        roundSize = Math.min(bitmap.getHeight(), bitmap.getWidth()) / 2f;
        Paint paint = new Paint();
        paint.setAntiAlias(true);
        canvas.drawARGB(0, 0, 0, 0);
        paint.setColor(Color.WHITE);
        RectF rectF = new RectF(0, 0, roundSize * 2, roundSize * 2);
        Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
        canvas.drawRoundRect(rectF, roundSize, roundSize, paint);
        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
        canvas.drawBitmap(bitmap, rect, new Rect(0, 0, Math.min(bitmap.getHeight(), bitmap.getWidth()), Math.min(bitmap.getHeight(), bitmap.getWidth())), paint);
        return outBitmap;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号