loadImage方法用于加载普通的图片,loadcircleImage方法用于加载圆形图片,loadcornerImage方法用于加载带有圆角的图片
都使用了Glide.with(context)来指定图片加载的上下文,使用.load(path)来指定要加载的图片路径。.error()方法用于在加载失败时显示的图片,.placeholder()方法用于在加载过程中显示的占位图片。
其中,.thumbnail(0.2f)方法用于设置缩略图,可以提高加载速度。.circleCrop()方法用于将图片裁剪为圆形,并且只显示圆形区域。.transform(new RoundedCorners(20))方法用于将图片裁剪为带有指定圆角的矩形。
另外,.skipMemoryCache(true)方法用于跳过内存缓存,.diskCacheStrategy(DiskCacheStrategy.ALL)方法用于设置磁盘缓存策略。
最后,通过.into(imageView)方法将加载的图片显示到指定的ImageView上。
package com.bw.day03.base.util; import android.content.Context; import android.widget.ImageView; import com.bumptech.glide.Glide; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.RoundedCorners; import com.bw.day03.R; public class GlideUtil { public static void loadImage(Context context, String path, ImageView imageView){ Glide.with(context) .load(path) .error(R.drawable.ic_launcher_foreground) .placeholder(R.drawable.ic_launcher_background) //缩略图 .thumbnail(0.2f) //三级缓存 .skipMemoryCache(true) .diskCacheStrategy(DiskCacheStrategy.ALL) .into(imageView); } //圆角图片 public static void loadciecleImage(Context context, String path, ImageView imageView){ Glide.with(context) .load(path) .error(R.drawable.ic_launcher_foreground) .placeholder(R.drawable.ic_launcher_background) //缩略图 .thumbnail(0.2f) .circleCrop() //三级缓存 .skipMemoryCache(true) .diskCacheStrategy(DiskCacheStrategy.ALL) .into(imageView); } public static void loadcornerImage(Context context, String path, ImageView imageView){ Glide.with(context) .load(path) .error(R.drawable.ic_launcher_foreground) .placeholder(R.drawable.ic_launcher_background) //缩略图 .thumbnail(0.2f) .transform(new RoundedCorners(20)) //三级缓存 .skipMemoryCache(true) .diskCacheStrategy(DiskCacheStrategy.ALL) .into(imageView); } }