0%

Android开发:生成圆角(圆形)图片

Android support v4包里已经包含了生成圆角(圆形)的方法,太贴心了.

       Bitmap src=BitmapFactory.decodeResource(getResources(),R.drawable.temp_avatar);
        RoundedBitmapDrawable roundedBitmapDrawable =
                RoundedBitmapDrawableFactory.create(getResources(),src);
        //设置圆角半径
        roundedBitmapDrawable.setCornerRadius(Math.max(src.getWidth(), src.getHeight()) / 2.0f);
        imageViewAvatar.setImageDrawable(roundedBitmapDrawable);

当圆角半径为宽高中最大值的一半时,生成的就是圆形图片.