本篇文章其实并不应该出现!【捂脸哭】
看过这篇文章的建议测试一下,本文中的示例,顺便对比其他百度到的示例。
写这篇文章的原因如下:
1.目前能百度到的glide圆角,圆形方案都是错误的
2.实际上glide在后续的新版本里提供了圆角圆形方案。
刚开始我在做项目的时候,采用了百度到的方案,结果发现百度到的代码效率极差,尤其是在做recycleView的时候,展示图片慢成狗。
于是我重新研究了glide代码,以及官方文档。
注:以下示例
圆形:
public class GlideCircleTransform extends BitmapTransformation {
private static final String ID = "com.xiaohe.www.lib.tools.glide.GlideCircleTransform";
private static final byte[] ID_BYTES = ID.getBytes(CHARSET);
@Override
protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) {
int size = Math.min(toTransform.getWidth(), toTransform.getHeight());
int x = (toTransform.getWidth() - size) / 2;
int y =