step1.添加依赖:compile 'com.github.bumptech.glide:glide:3.7.0'
step2.添加权限:<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
step3.最简单使用:Glide.with(this).load(url).into(iv_icon);
step4.复杂使用
Glide.with(this)
.load(UsageExampleListViewAdapter.eatFoodyImages[0])
.placeholder(R.mipmap.ic_launcher) //设置占位图
.error(R.mipmap.future_studio_launcher) //设置错误图片
.crossFade() //设置淡入淡出效果,默认300ms,可以传参
.dontAnimate() //不显示动画效果
.into(iv_icon);
step5.获得bitmap
SimpleTarget target = new SimpleTarget() {
@Override
public void onResourceReady(Object resource, GlideAnimation glideAnimation) {
imageView.setImageBitmap((Bitmap) resource);
}
};
Glide.with(this)
.load(url)
.asBitmap()
.placeholder(R.mipmap.ic_launcher)
.into(target);
step6.如何要改变图标样式
添加依赖:compile 'jp.wasabeef:glide-transformations:2.0.1'
//圆形裁剪
Glide.with(this)
.load(url)
.bitmapTransform(new CropCircleTransformation(this))
.into(imageView);
//圆角处理
Glide.with(this)
.load(url)
.bitmapTransform(new RoundedCornersTransformation(this,30,0, RoundedCornersTransformation.CornerType.ALL))
.into(imageView);
//灰度处理
Glide.with(this)
.load(url)
.bitmapTransform(new GrayscaleTransformation(this))
.into(imageView);
源码地址:http://download.csdn.net/detail/daidaishuiping/9778355