Java Code Examples for com.bumptech.glide.DrawableTypeRequest#centerCrop()

The following examples show how to use com.bumptech.glide.DrawableTypeRequest#centerCrop() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageLoader.java    From HttpRequest with Apache License 2.0 5 votes vote down vote up
/**
 * 图片加载
 * @author leibing
 * @createTime 2016/8/15
 * @lastModify 2016/8/15
 * @param context 上下文
 * @param imageView 图片显示控件
 * @param localPath 图片本地链接
 * @param defaultImage 默认占位图片
 * @param errorImage 加载失败后图片
 * @param  isCropCircle 是否圆角
 * @return
 */
public void load(Context context, ImageView imageView, File localPath, Drawable defaultImage, Drawable errorImage , boolean isCropCircle){
    // 图片加载库采用Glide框架
    DrawableTypeRequest request = Glide.with(context).load(localPath);
    // 设置scaleType
    request.centerCrop();
    // 圆角裁切
    if (isCropCircle)
        request.bitmapTransform(new CropCircleTransformation(context));
    request.thumbnail(0.1f) //用原图的1/10作为缩略图
            .placeholder(defaultImage) //设置资源加载过程中的占位Drawable
            .crossFade() //设置加载渐变动画
            .priority(Priority.NORMAL) //指定加载的优先级,优先级越高越优先加载,
            // 但不保证所有图片都按序加载
            // 枚举Priority.IMMEDIATE,Priority.HIGH,Priority.NORMAL,Priority.LOW
            // 默认为Priority.NORMAL
            .fallback(null) //设置model为空时要显示的Drawable
            // 如果没设置fallback,model为空时将显示error的Drawable,
            // 如果error的Drawable也没设置,就显示placeholder的Drawable
            .error(errorImage) //设置load失败时显示的Drawable
            .skipMemoryCache(true) //设置跳过内存缓存,但不保证一定不被缓存
            // (比如请求已经在加载资源且没设置跳过内存缓存,这个资源就会被缓存在内存中)
            .diskCacheStrategy(DiskCacheStrategy.RESULT) //缓存策略DiskCacheStrategy.SOURCE:
            // 缓存原始数据,DiskCacheStrategy.RESULT:
            // 缓存变换(如缩放、裁剪等)后的资源数据,
            // DiskCacheStrategy.NONE:什么都不缓存,
            // DiskCacheStrategy.ALL:缓存SOURC和RESULT。
            // 默认采用DiskCacheStrategy.RESULT策略,
            // 对于download only操作要使用DiskCacheStrategy.SOURCE
            .into(imageView);
}
 
Example 2
Source File: ImageLoader.java    From LbaizxfPulltoRefresh with Apache License 2.0 5 votes vote down vote up
/**
 * 图片加载
 * @author leibing
 * @createTime 2016/8/15
 * @lastModify 2016/8/15
 * @param context 上下文
 * @param imageView 图片显示控件
 * @param localPath 图片本地链接
 * @param defaultImage 默认占位图片
 * @param errorImage 加载失败后图片
 * @param  isCropCircle 是否圆角
 * @return
 */
public void load(Context context, ImageView imageView, File localPath, Drawable defaultImage, Drawable errorImage , boolean isCropCircle){
    // 图片加载库采用Glide框架
    DrawableTypeRequest request = Glide.with(context).load(localPath);
    // 设置scaleType
    request.centerCrop();
    // 圆角裁切
    if (isCropCircle)
        request.bitmapTransform(new CropCircleTransformation(context));
    request.thumbnail(0.1f) //用原图的1/10作为缩略图
            .placeholder(defaultImage) //设置资源加载过程中的占位Drawable
            .crossFade() //设置加载渐变动画
            .priority(Priority.NORMAL) //指定加载的优先级,优先级越高越优先加载,
            // 但不保证所有图片都按序加载
            // 枚举Priority.IMMEDIATE,Priority.HIGH,Priority.NORMAL,Priority.LOW
            // 默认为Priority.NORMAL
            .fallback(null) //设置model为空时要显示的Drawable
            // 如果没设置fallback,model为空时将显示error的Drawable,
            // 如果error的Drawable也没设置,就显示placeholder的Drawable
            .error(errorImage) //设置load失败时显示的Drawable
            .skipMemoryCache(true) //设置跳过内存缓存,但不保证一定不被缓存
            // (比如请求已经在加载资源且没设置跳过内存缓存,这个资源就会被缓存在内存中)
            .diskCacheStrategy(DiskCacheStrategy.RESULT) //缓存策略DiskCacheStrategy.SOURCE:
            // 缓存原始数据,DiskCacheStrategy.RESULT:
            // 缓存变换(如缩放、裁剪等)后的资源数据,
            // DiskCacheStrategy.NONE:什么都不缓存,
            // DiskCacheStrategy.ALL:缓存SOURC和RESULT。
            // 默认采用DiskCacheStrategy.RESULT策略,
            // 对于download only操作要使用DiskCacheStrategy.SOURCE
            .into(imageView);
}
 
Example 3
Source File: GlideImageSpec.java    From litho-glide with MIT License 4 votes vote down vote up
@OnMount
static void onMount(ComponentContext c, ImageView imageView,
    @Prop(optional = true) String imageUrl, @Prop(optional = true) File file,
    @Prop(optional = true) Uri uri, @Prop(optional = true) Integer resourceId,
    @Prop(optional = true) RequestManager glideRequestManager,
    @Prop(optional = true, resType = DRAWABLE) Drawable failureImage,
    @Prop(optional = true, resType = DRAWABLE) Drawable fallbackImage,
    @Prop(optional = true, resType = DRAWABLE) Drawable placeholderImage,
    @Prop(optional = true) DiskCacheStrategy diskCacheStrategy,
    @Prop(optional = true) RequestListener requestListener,
    @Prop(optional = true) boolean asBitmap, @Prop(optional = true) boolean asGif,
    @Prop(optional = true) boolean crossFade, @Prop(optional = true) int crossFadeDuration,
    @Prop(optional = true) boolean centerCrop, @Prop(optional = true) boolean fitCenter,
    @Prop(optional = true) boolean skipMemoryCache, @Prop(optional = true) Target target) {

  if (imageUrl == null && file == null && uri == null && resourceId == null) {
    throw new IllegalArgumentException(
        "You must provide at least one of String, File, Uri or ResourceId");
  }

  if (glideRequestManager == null) {
    glideRequestManager = Glide.with(c.getAndroidContext());
  }

  DrawableTypeRequest request;

  if (imageUrl != null) {
    request = glideRequestManager.load(imageUrl);
  } else if (file != null) {
    request = glideRequestManager.load(file);
  } else if (uri != null) {
    request = glideRequestManager.load(uri);
  } else {
    request = glideRequestManager.load(resourceId);
  }

  if (request == null) {
    throw new IllegalStateException("Could not instantiate DrawableTypeRequest");
  }

  if (diskCacheStrategy != null) {
    request.diskCacheStrategy(diskCacheStrategy);
  }

  if (asBitmap) {
    request.asBitmap();
  }

  if (asGif) {
    request.asGif();
  }

  if (crossFade) {
    request.crossFade();
  }

  if (crossFadeDuration != DEFAULT_INT_VALUE) {
    request.crossFade(crossFadeDuration);
  }

  if (centerCrop) {
    request.centerCrop();
  }

  if (failureImage != null) {
    request.error(failureImage);
  }

  if (fallbackImage != null) {
    request.fallback(fallbackImage);
  }

  if (fitCenter) {
    request.fitCenter();
  }

  if (requestListener != null) {
    request.listener(requestListener);
  }

  if (placeholderImage != null) {
    request.placeholder(placeholderImage);
  }

  request.skipMemoryCache(skipMemoryCache);

  if (target != null) {
    request.into(target);
  } else {
    request.into(imageView);
  }
}