admin
2021-03-29 405e8b2d2ad9a2d6d51cd65173b42c9fcde0ce4f
library-common/src/com/lcjian/library/util/glide/GlideRoundTransform.java
@@ -11,8 +11,11 @@
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
import com.bumptech.glide.load.resource.bitmap.TransformationUtils;
import com.bumptech.glide.util.Util;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.security.MessageDigest;
/**
@@ -46,7 +49,9 @@
    @Override
    protected Bitmap transform(BitmapPool pool, Bitmap toTransform,
                               int outWidth, int outHeight) {
        return roundCrop(pool, toTransform);
        //处理centercrop
        Bitmap bitmap = TransformationUtils.centerCrop(pool, toTransform, outWidth, outHeight);
        return roundCrop(pool, bitmap == null ? toTransform : bitmap);
    }
    private static Bitmap roundCrop(BitmapPool pool, Bitmap source) {
@@ -72,11 +77,23 @@
    @Override
    public int hashCode() {
        return ID.hashCode();
        return Util.hashCode(ID.hashCode(),
                Util.hashCode(radius));
    }
    @Override
    public boolean equals(Object o) {
        if (o instanceof GlideRoundTransform) {
            GlideRoundTransform other = (GlideRoundTransform) o;
            return radius == other.radius;
        }
        return false;
    }
    @Override
    public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {
        messageDigest.update(ID_BYTES);
        byte[] radiusData = ByteBuffer.allocate(4).putInt((int) radius).array();
        messageDigest.update(radiusData);
    }
}