直接上源码。注释得已经很清晰了,直接调用即可。

 package com.liuguilin.lovewallpaper.utils;
/*
* Created by 火龙裸先生 on 2017/3/3 0003.
*/ import android.content.Context;
import android.widget.ImageView; import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.SimpleTarget; public class GlideUtils { /**
* Glide特点
* 使用简单
* 可配置度高,自适应程度高
* 支持常见图片格式 Jpg png gif webp
* 支持多种数据源 网络、本地、资源、Assets 等
* 高效缓存策略 支持Memory和Disk图片缓存 默认Bitmap格式采用RGB_565内存使用至少减少一半
* 生命周期集成 根据Activity/Fragment生命周期自动管理请求
* 高效处理Bitmap 使用Bitmap Pool使Bitmap复用,主动调用recycle回收需要回收的Bitmap,减小系统回收压力
* 这里默认支持Context,Glide支持Context,Activity,Fragment,FragmentActivity
*/ //默认加载
public static void loadImageView(Context mContext, String path, ImageView mImageView) {
Glide.with(mContext).load(path).into(mImageView);
} //加载指定大小
public static void loadImageViewSize(Context mContext, String path, int width, int height, ImageView mImageView) {
Glide.with(mContext).load(path).override(width, height).into(mImageView);
} //填充
public static void loadImageCrop(Context mContext, String path, ImageView mImageView) {
Glide.with(mContext).load(path).centerCrop().diskCacheStrategy(DiskCacheStrategy.ALL).into(mImageView);
} //设置加载中以及加载失败图片
public static void loadImageViewLoding(Context mContext, String path, ImageView mImageView, int lodingImage, int errorImageView) {
Glide.with(mContext).load(path).placeholder(lodingImage).error(errorImageView).into(mImageView);
} //设置加载中以及加载失败图片并且指定大小
public static void loadImageViewLodingSize(Context mContext, String path, int width, int height, ImageView mImageView, int lodingImage, int errorImageView) {
Glide.with(mContext).load(path).override(width, height).placeholder(lodingImage).error(errorImageView).into(mImageView);
} //设置跳过内存缓存
public static void loadImageViewCache(Context mContext, String path, ImageView mImageView) {
Glide.with(mContext).load(path).skipMemoryCache(true).into(mImageView);
} //设置下载优先级
public static void loadImageViewPriority(Context mContext, String path, ImageView mImageView) {
Glide.with(mContext).load(path).priority(Priority.NORMAL).into(mImageView);
} /**
* 策略解说:
* <p>
* all:缓存源资源和转换后的资源
* <p>
* none:不作任何磁盘缓存
* <p>
* source:缓存源资源
* <p>
* result:缓存转换后的资源
*/ //设置缓存策略
public static void loadImageViewDiskCache(Context mContext, String path, ImageView mImageView) {
Glide.with(mContext).load(path).diskCacheStrategy(DiskCacheStrategy.ALL).into(mImageView);
} /**
* api也提供了几个常用的动画:比如crossFade()
*/ //设置加载动画
public static void loadImageViewAnim(Context mContext, String path, int anim, ImageView mImageView) {
Glide.with(mContext).load(path).animate(anim).into(mImageView);
} /**
* 会先加载缩略图
*/ //设置缩略图支持
public static void loadImageViewThumbnail(Context mContext, String path, ImageView mImageView) {
Glide.with(mContext).load(path).thumbnail(0.1f).into(mImageView);
} /**
* api提供了比如:centerCrop()、fitCenter()等
*/ //设置动态转换
public static void loadImageViewCrop(Context mContext, String path, ImageView mImageView) {
Glide.with(mContext).load(path).centerCrop().into(mImageView);
} //设置动态GIF加载方式
public static void loadImageViewDynamicGif(Context mContext, String path, ImageView mImageView) {
Glide.with(mContext).load(path).asGif().into(mImageView);
} //设置静态GIF加载方式
public static void loadImageViewStaticGif(Context mContext, String path, ImageView mImageView) {
Glide.with(mContext).load(path).asBitmap().into(mImageView);
} //设置监听的用处 可以用于监控请求发生错误来源,以及图片来源 是内存还是磁盘 //设置监听请求接口
public static void loadImageViewListener(Context mContext, String path, ImageView mImageView, RequestListener<String, GlideDrawable> requstlistener) {
Glide.with(mContext).load(path).listener(requstlistener).into(mImageView);
} //项目中有很多需要先下载图片然后再做一些合成的功能,比如项目中出现的图文混排 //设置要加载的内容
public static void loadImageViewContent(Context mContext, String path, SimpleTarget<GlideDrawable> simpleTarget) {
Glide.with(mContext).load(path).centerCrop().into(simpleTarget);
} //清理磁盘缓存
public static void GuideClearDiskCache(Context mContext) {
//理磁盘缓存 需要在子线程中执行
Glide.get(mContext).clearDiskCache();
} //清理内存缓存
public static void GuideClearMemory(Context mContext) {
//清理内存缓存 可以在UI主线程中进行
Glide.get(mContext).clearMemory();
}
}

图片加载库Glide的封装工具类,方便以后使用的更多相关文章

  1. Google图片加载库Glide的简单封装GlideUtils

    Google图片加载库Glide的简单封装GlideUtils 因为项目里用的Glide的地方比较多,所有简单的封装了以下,其实也没什么,就是写了个工具类,但是还是要把基础说下 Glide的Githu ...

  2. Android 图片加载库Glide 实战(二),占位符,缓存,转换自签名高级实战

    http://blog.csdn.net/sk719887916/article/details/40073747 请尊重原创 : skay <Android 图片加载库Glide 实战(一), ...

  3. android图片加载库Glide

    什么是Glide? Glide是一个加载图片的库,作者是bumptech,它是在泰国举行的google 开发者论坛上google为我们介绍的,这个库被广泛的运用在google的开源项目中. Glide ...

  4. android 图片加载库 Glide 的使用介绍

    一:简介 在泰国举行的谷歌开发者论坛上,谷歌为我们介绍了一个名叫 Glide 的图片加载库,作者是bumptech.这个库被广泛的运用在google的开源项目中,包括2014年google I/O大会 ...

  5. Google推荐的图片加载库Glide介绍

    英文原文 Introduction to Glide, Image Loader Library for Android, recommended by Google 译文首发  http://jco ...

  6. Google推荐的图片加载库Glide

    英文原文 Introduction to Glide, Image Loader Library for Android, recommended by Google 首发地址  http://jco ...

  7. Aandroid 图片加载库Glide 实战(一),初始,加载进阶到实践

    原文: http://blog.csdn.net/sk719887916/article/details/39989293 skay 初识Glide 为何使用 Glide? 有经验的 Android ...

  8. Android图片加载库的理解

    前言     这是“基础自测”系列的第三篇文章,以Android开发需要熟悉的20个技术点为切入点,本篇重点讲讲Android中的ImageLoader这个库的一些理解,在Android上最让人头疼是 ...

  9. fackbook的Fresco (FaceBook推出的Android图片加载库-Fresco)

    [Android开发经验]FaceBook推出的Android图片加载库-Fresco   欢迎关注ndroid-tech-frontier开源项目,定期翻译国外Android优质的技术.开源库.软件 ...

随机推荐

  1. ViewPage最全解析

    简单说明: ViewPager是android扩展包v4包中的类,直接继承了ViewGroup类,和LinearLayout等布局一样,都是一个容器,需要在里面添加我们想要显示的内容. 一.在xml中 ...

  2. Spring Security构建Rest服务-0801-短信验证码发送

    实现短信验证码登录 开发短信验证码接口 校验短信验证码并登录 短信验证码和图片验证码开发思路类似: 1,我们访问一个controller 2,在controller里调用短信验证码生成接口生成验证码 ...

  3. SQLServer2005重建索引

    今天发现一个页面运行很慢,用SQL Server Profiler抓出了一条运行时间为12s的sql ) and wfinstance is not null and wftbrq>='2016 ...

  4. Python单行注释与多行注释

    >>> print "hello,world"hello,world>>> 2+24#单行注释 """每行代码的后 ...

  5. 如何虚拟机里安装win7操作系统

    不多说,直接上干货! Windows Server 2003.2008.2012系统的安装 关于给电脑换系统,很多人会花钱去电脑店里换,或者是下载Ghost系统.但这些系统都不是微软原版的,制作者已经 ...

  6. Ripple(瑞波币)validator-keys-tool 配置验证器

    目录 Ripple(瑞波币)validator-keys-tool配置验证器 验证器密钥工具指南 验证器密钥 验证器令牌(Validator Keys) public_key撤销 签名 Ripple( ...

  7. Spring配置Quartz任务调度、及 ThreadPool 线程池

    ONE.除了引入 Spring 相关的 jar 包,还要引入 Quartz 的 jar 包 <dependency> <groupId>org.springframework& ...

  8. 回溯法求解n皇后和迷宫问题

    回溯法是一种搜索算法,从某一起点出发按一定规则探索,当试探不符合条件时则返回上一步重新探索,直到搜索出所求的路径. 回溯法所求的解可以看做解向量(n皇后坐标组成的向量,迷宫路径点组成的向量等),所有解 ...

  9. api.openWin

    打开window 若 window 已存在,则会把该 window 显示到最前面,如果 url 和之前的 url 有变化,或者 reload 为 true 时,页面会刷新,但是该 window 里面已 ...

  10. Runtime初识

    什么是Runtime   我们写的代码在程序运行过程中都会被转化成runtime的C代码执行,例如[target doSomething];会被转化成objc_msgSend(target, @sel ...