zoukankan      html  css  js  c++  java
  • Glide加载圆角

    public class GlideTransformUtil extends BitmapTransformation {

    private static float radius = 0f;

    public GlideTransformUtil(Context context) {
    this(context, 4);
    }

    public GlideTransformUtil(Context context, int dp) {
    super(context);
    this.radius = Resources.getSystem().getDisplayMetrics().density * dp;
    }

    @Override protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
    return roundCrop(pool, toTransform);
    }

    private static Bitmap roundCrop(BitmapPool pool, Bitmap source) {
    if (source == null) return null;

    Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
    if (result == null) {
    result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
    }

    Canvas canvas = new Canvas(result);
    Paint paint = new Paint();
    paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
    paint.setAntiAlias(true);
    RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight());
    canvas.drawRoundRect(rectF, radius, radius, paint);
    return result;
    }

    @Override public String getId() {
    return getClass().getName() + Math.round(radius);
    }
    }

    使用方式:
    .transform(new GlideTransformUtil(AppContext.getAppContext()))
    .into(holder.ivImg);
  • 相关阅读:
    HDU4714+三分
    HDU1465+递推
    HDU1437+模拟
    HDU1796+容斥原理
    HDU1432+几何
    Linux---Ls命令 初级实现
    HDU1411+四面体的体积
    HDU1412
    HDU1431+简单题
    请定义一个交通工具(Vehicle)的类,其中有: 属性:速度(speed),体积(size)等等
  • 原文地址:https://www.cnblogs.com/banzhuan/p/6769496.html
Copyright © 2011-2022 走看看