1.布局文件中设置ImageView的参数

android:scaleType="fitXY"

2.创建圆形的方法

public static Bitmap circleBitmap(Bitmap source) {    int width = source.getWidth();    Bitmap bitmap = Bitmap.createBitmap(width, width, Bitmap.Config.ARGB_8888);    Canvas canvas = new Canvas(bitmap);    Paint paint = new Paint();    paint.setAntiAlias(true);    canvas.drawCircle(width / 2, width / 2, width / 2, paint);    //设置图片相交情况下的处理方式    //setXfermode:设置当绘制的图像出现相交情况时候的处理方式的,它包含的常用模式有:    //PorterDuff.Mode.SRC_IN 取两层图像交集部分,只显示上层图像    //PorterDuff.Mode.DST_IN 取两层图像交集部分,只显示下层图像    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));    canvas.drawBitmap(source, 0, 0, paint);    return bitmap;}

3.调用方法(如果使用Picasso加载网络图片,可以参考下面代码)

Picasso.with(this.getActivity()).load(user.getImageurl()).transform(new Transformation() {    @Override    public Bitmap transform(Bitmap bitmap) {        Bitmap bitmap1 = BitmapUtils.circleBitmap(bitmap);        bitmap.recycle();        return bitmap1;    }    @Override    public String key() {        return "";    }}).into(ivMeIcon);

(注:如果想先压缩成正方形在圆形处理,可以先调用下面的方法)

//图片压缩public static Bitmap zoom(Bitmap source,float width,float height){    Matrix matrix=new Matrix();    matrix.postScale(width/source.getWidth(),height/source.getHeight());    Bitmap bitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, false);    return bitmap;}

Imageview图片圆形显示_第1张图片

更多相关文章

  1. android调用图库获取图片显示在img中
  2. Android 使用Drawable实现圆角与圆形图案
  3. Android Base64转换图片,SimpleAdapter动态显示Bitmap图片
  4. Android使用Base64将图片与String的转换
  5. Android 判断两个图片相等
  6. Android充电进度获取,圆形波浪进度展示
  7. android 图片浏览器
  8. android之4.0控件switch自定义开关背景图片和控制宽度
  9. Android:指定分辨率和清晰度的图片压缩方法源码

随机推荐

  1. android自定义主题样式
  2. Android商品规格流式布局运用RecyclerVie
  3. android 自带的主题theme
  4. Android(安卓)系统自带样式Android:theme
  5. EditText控件常用属性
  6. android inputtype属性
  7. Android(安卓)EditText各种属性及作用
  8. Android应用开发——系统自带样式Android
  9. Android开发_TextView跑马灯
  10. Android:Material Design(四) UI控件